This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a big problem; I am new with thread (maybe little newer in Java), and I need to do some serious work, so I am asking for help; I need to do that on some click (by the user) web app create thread witch will run two tasks (for that user)and those two tasks will be go to sleep for some time (define by the user) and run again (each task has its own time). I will repeat: 1 user, 1 thread, two tasks with diferent time of executing, and when user come off, everything still runing (I have database, this is not a problem). And then second user come in he has option to create same thread with two same tasks (but he can set diferent times for each). Normally these two tasks write and read something in/from database for his user (but these isnt the point; let we have that task1 do system.out.println("I am task"+one+"from"+first+"user"). and task2 do system.out.println("I am task"+two+"from"+first+"user"), and so on for seconod user.. )
I cant figure out how can I loop that for eternaly, pass new threads, and acces particulary thread for deleting her (bay the user id). Maybe I need some vector lists, but I dont now how to use it. I have looked at some thread books, but nobody have my exaple.
Does anybody has some similar example code, so I can study it? Tnx in advance Kind regardes
See if Timer and TimerTask do what you want. You create a TimerTask and pass it to a Timer to schedule execution. You could create Task1 and Task2 to do whatever they want to do.
Then again, if this is like a school assignment and you're being graded on making your own mechanism to use a single thread for a number of deferred tasks, we can talk through duplicating some of what Timer does.
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
Yup, that's the stuff. I noticed it's not on a Sun site, though. You'd be more sure to find the very latest versions of things there. Google for "sun anything tutorial", eg "sun timer tutorial", almost always comes up a winner.
Let us know how it works out!
Joined: Aug 21, 2006
I have an error where it saying: <identifier> expected; what the hack is that means?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com