wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Sharing resources between two TimerTasks running in two separate Timer Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Sharing resources between two TimerTasks running in two separate Timer Thread" Watch "Sharing resources between two TimerTasks running in two separate Timer Thread" New topic
Author

Sharing resources between two TimerTasks running in two separate Timer Thread

Joshy Thomas
Greenhorn

Joined: Jul 23, 2004
Posts: 13
I have two scheduled TimerTasks running in two java.util.Timer threads and these tasks share a common database connection pool using synchronized methods. Program runs very very slow and I could not notice any thread locks. But the same program run very fast when two separate database
connection is maintained by each TimerTask. I have not seen any examples like this, but theoretically it should work. But I don't understand why program takes more time while sharing resources.

Any idea why the Timer Threads behave this way..


<a href="http://www.FindTaxService.com" target="_blank" rel="nofollow">Free Tax Software</a>
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

Using this forum to advertize is low.


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, we do have a "Blatant Advertising" forum here, and posts that are blatant advertising do get moved over there. But advertising in people's sigs is another question. If they aren't too blatant then we (the bartenders and sheriffs) are going to let them slide by.

However other ranchers are perfectly free to express their own opinions (in a nice way, of course).
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hmmm, Joshy must have removed the offending sig?

Just some random ideas ... don't be offended if they're too simple minded ...

How long do you figure you stay in the synchronized blocks? Your threads will have to go through those single file so they can slow you down.

You wouldn't have a connection pool with one connection in it would you? If there are as many or more connections than threads there should always be one available. Unless maybe you forgot to put them back and the pool was creating new ones all the time.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joshy Thomas
Greenhorn

Joined: Jul 23, 2004
Posts: 13
Yes, I removed the signature not to offend some ranchers and is adding it back as not every body is offened.. Sorry I can't make everybody happy..

Now.. Back to the point...

Connection pool (based on Apache dhcp ) is pre created with 5 connections. Each thread (total 2) take one connection, fire some sqls and close it.

The threads are Timer Threads and is running separate TimerTasks. The connection is taken from the TimerTasks.

Is there any difference between a custom Thread based on java.lang.Thread and that created by the java.util.Timer Class ?.

Googling doesn't help much
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Well, your result is not what I'd expect either. Can you share some of the code that is using connections? Maybe we'll spot something in there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing resources between two TimerTasks running in two separate Timer Thread
 
Similar Threads
how to break date
TimerTask, Thread
Thread for a given time window
Why are TimerTasks Runnable?
questions java.util.Timer