Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Timer & TimerTask - Name of Timer Object  RSS feed

 
SanthanaKrishnan Chandrasekaran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to schedule a task say a (java class) task



which extends.
My Timer object



calls the class using




a new thread which performs the schedule starts.

Another Timer obj Timer(name2) calls the same TimerTask - MyTask using timer.schedule from a different method.

Is there any possibility that i get the timer object's name.
Mean to say



I want this name1 and name2 in my task class .

Is there any possibility?
Cos i have to perform the same task with diff names under diff threads with corresponding names.

Its very urgent.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The name of the timer is used as the name of the Timer's thread, accessible by calling getName() on the Thread. When a task is executing, Thread.currentThread() will return the timer thread; so in your Runnable, just call Thread.currentThread().getName() to get the name of the timer.

Easy, huh?
 
SanthanaKrishnan Chandrasekaran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!

Thanks Hill
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Nicknames and "handles" aren't enough. I'm pretty sure you had a valid display name when I answered this question, and you've since changed it.

You can change your display name back here. Thanks!
 
SanthanaKrishnan Chandrasekaran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changed.

Thanks for your timely help.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!