• Post Reply Bookmark Topic Watch Topic
  • New Topic

run method

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

My program needs to query the DataBase every couple of seconds and get the value of one paricular column from the Db.
Depending on the value (result) I have a switch case statement.

I am thinking about using Timer and timerTask. but my question can the run method in the timerTask return the value queried from the Db??

here is the very basic code to get an idea what i am trying to do..


public class VoidETCarrierAction extends VoidConfirmAction
{
long delay = 1000*2;//(2 seconds)
Timer timer = new Timer();
TimerTask voidETCarrierTask = new voidETCarrierTask();
timer.schedule(voidETCarrierTask,delay);
//if carrier_void_status <> waiting
// get carrier_void_result
//case(result)
//result:error
//result:confirm ,travelDocDAO.unlockDoc(dcNbr,docSeqNbr)
//return to user the listPage
class voidETCarrierTask extends TimerTask
{
TimerTask voidETCarrierTask = new voidETCarrierTask();

public void run()
{
//every Couple of seconds
//1. select database_row_locking to check carrier_void_result


}


}

}

can someone please let me know how to implement it??
thanks,
Trupti
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use an instance variable in your voidETCarrierTask class. set that variable inside run() method and have a property method i.e.

String getAttribute(){
return str;
}

it may help ....

we cant change the run() of TimerTask method to return something other than void.
[ August 31, 2004: Message edited by: adeel ansari ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically with recurring tasks you put the code you want executed either in the run() method of the task or, with an eye toward maintainence, in some other helper class that the task's run() method calls. For simplicity, let's put it into the task like you've started.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!