Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Threads Question...

Status
Not open for further replies.

mfalomir

Technical User
Feb 6, 2003
78
MX
Hi, Im working with threads but Im having a problem, my first approach was to create a new Thread everytime I need it, once the thread was created it creates connection to a data base and perform some stuff...but things started to get a little slow :) So what Im doing it is to create N threads to be available for use, and every thread will have its own DB connection initiated and opened since the beginning, so when it's needed everything goes a little faster because the connection it's already opened. My problem its that once a thread finishes its job I want to keep it available for reusability, and my threads are dying just after they finished with its run process....

Any suggestions ?

Thanks in advanced
Regards
 
Threads aren't reusable.
You may not start a Thread twice.

But you may prevent it from exiting.

Make an endless-loop which will only exit when explicitly asked, and give it a state - (running, sleeping, halted).

seeking a job as java-programmer in Berlin:
 
Why not use a tried-and-tested 'connection pool', instead? There's one at


Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
i did it once with the Timer Class so: from main method i initialized 8 Threads. In a Thread Class i made an object from the timer class that starts sheduling processes. The Program doesn't interrupt, but starts in time periods i wish over and over again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top