The moose likes Threads and Synchronization and the fly likes Timer & TimerTask - Name of Timer Object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Timer & TimerTask - Name of Timer Object" Watch "Timer & TimerTask - Name of Timer Object" New topic
Author

Timer & TimerTask - Name of Timer Object

SanthanaKrishnan Chandrasekaran
Greenhorn

Joined: Dec 11, 2006
Posts: 5
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
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

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?


[Jess in Action][AskingGoodQuestions]
SanthanaKrishnan Chandrasekaran
Greenhorn

Joined: Dec 11, 2006
Posts: 5
Great!

Thanks Hill
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

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

Joined: Dec 11, 2006
Posts: 5
Changed.

Thanks for your timely help.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Timer & TimerTask - Name of Timer Object
 
Similar Threads
Call action class from timertask's run method
Set Timer
Problem with Timer and TimerTask
[Need recommendation] Do a repetitive task daily
java.util.Timer inside Runnable?