control child thread from parent thread
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Senthil_Ram
Posted On:   Wednesday, August 7, 2002 09:09 AM

Hi All, I am a newbie to java and thread programming. I am writing up a small thread program for my database to simulate various actions, like insert, update, delete. All i am trying to do is, create several threads, using each thread establish connection to the database and execute the statement. rightnow, i am testing with simple statement (commit) to make sure the thread and other stuff works and it does. Yes, i am using Oracle's connection pool, to create N connections before i create N threads. But the problem i am having is, if i want to create 5 threads which issues a commit what java doing is, sometime it uses only 3 or 4 connections and as soon as the first thread does the job 4th or 5th thread reuses the same conn   More>>

Hi All,


I am a newbie to java and thread programming. I am writing up a small thread program for my database to simulate various actions, like insert, update, delete. All i am trying to do is, create several threads, using each thread establish connection to the database and execute the statement. rightnow, i am testing with simple statement (commit) to make sure the thread and other stuff works and it does. Yes, i am using Oracle's connection pool, to create N connections before i create N threads.


But the problem i am having is, if i want to create 5 threads which issues a commit what java doing is, sometime it uses only 3 or 4 connections and as soon as the first thread does the job 4th or 5th thread reuses the same connection. i dont want that to be happened. if i want to test with 5 threads, then 5 connections has to be created and used by all threads. For this i want to suspend or wait
as soon as each thread acquired connection from the connection pool and look for some flag and it should be controlled by parent thread. If i see all threads ac
quired connection, then i should turn on the flag and start firing the statement. would that be possible. i have tried various options using Paul Hyde's example, but couldnt get expected result. Anyone who come across the same situation or have any idea which might help me would be appreciated. any urls or examples would give me a better thought, if not, thats fine.




thanks,


senthil

   <<Less

Re: control child thread from parent thread

Posted By:   Simon_Ablett  
Posted On:   Wednesday, August 7, 2002 12:57 PM

My advice would be to wait until you have a problem before you try to solve it. What is so important about whether you have four or five threads running? The chances are that your program will spend more time waiting for a database op to return than it will doing anything else. The fact that you are only performing very simple actions probably means that you are coming across thread starvation issues. That is to say that the first four threads are using so many cycles that the fifth doesn't get the chance to do anything. One way to prove whether or not this is the case would be to have each thread call 'Thread.sleep' for a minimal period (each 100 milliseconds) after each op.

If you suspend the operation of all other threads once one thread gets the right to operate you may as well not use multi-threading.

Regards.
About | Sitemap | Contact