File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sharing resources between two TimerTasks running in two separate Timer Thread

 
Joshy Thomas
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using this forum to advertize is low.
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joshy Thomas
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic