• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Timer & TimerTask - Name of Timer Object

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great!

Thanks Hill
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changed.

Thanks for your timely help.
 
That new kid is a freak. Show him this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic