• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Threads  RSS feed

 
Bindu Dharmavaram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm new to programming Threads. I have a question from my observation of threads. Im running the following application.
class x {
for(int i=0;i<2;i++)
mySub s = new mySub();
Thread t = new Thread(s);
t.start();
}
class mySub implements Runnable {
public void run() {
while (true) {
processQueueMessage();
}
}
}
In the above scenario, mySub class connects to a AQ and processes
messages in the Queue. Each object establishes its own session to the database and shares nothing with another thread. I have not tried to use any I/O operations for this example for the convenience.
If the use one thread to process 50 messages in a queue, it takes 7 seconds. (Practically, from the minute it starts receiving message from the queue).
If I use 2 threads for the same scenario, though, they are using the same queue, and established different db sessions, the time comes down to 5~6 seconds.
After looking at each line of code, I'm very sure, these threads are not using any shared resources. I'm running this test on solaris, which does preemptive scheduling.
My question is that if there are no shared resources between threads, why am I not seeing a good performance hop here ? May not be (31/2 seconds), but, why not 4 seconds at least ? Is there anything Im missing here ? It is a single processor machine.
Thanks
Bindu
 
Iain Lowe
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would tentatively say that the reason you see no performance increase is that you are processing a relatively small number of messages using what is probably (hopefully) a small processing method. If your method took longer to execute or you had more messages in your queue I think you would see a more impressive gain in performance.
Try putting 1,000 messages in your queue and do the same experiment over again. I think you will see that having the extra Thread working will increase the performance.
 
Bindu Dharmavaram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Iain,
Thanks for the reply. But, that didn't seem to make much difference. Even, it seems to have worsened the situation.
Here's what I'm doing after getting the message from queue.
1. Get message properties (strings)
2. LDAP lookups with these properties -- Even the LDAP connection is seperate for each thread.
3. Some string manipulations.
4. create a new message from these and enqueue into another queue. I have commented out the code where it does enqueing into another queue for testing...
LDAP connections are definitely not serialized and a new JMS session is created for each thread.
I don't understand what could be going wrong here. I'm confused at this point.
Bindu
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!