Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

background thread monitoring database  RSS feed

 
Kyle Fernandes
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How can one create a thread that runs in the background of the main program that periodically checks a database for changes. If a change is picked up a method will be called.
Any help would be appreciated.

thank you.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? What failed?
 
Kyle Fernandes
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iv tried to create a simple thread that checks the database every 5 seconds but im getting errors on the sleep function, it doesnt recognise it..Im just trying to make sure that this approach is good and possible.

here is my code so far:
 
Jean-Christophe Blanchard
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not using a Timer ?
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Quartz also to achieve this.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The sleep problem is because you didn't define a sleep method. You probably want Thread.sleep()
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!