• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

isInterrupted -- Simple yet Pretty Confused

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A very simple question i guess, but i even have problem with it.
I am pretty confused with isInterrupted which in the foll program gives error.
class interruption implements Runnable{
public void run()
{
Thread y = Thread.currentThread();
for(int i=0;i<15;i++)
{
System.out.println(y.getName().isInterrupted()); //error here
}}
public static void main(String args[]){
interruption i = new interruption();
Thread t = new Thread(i,"New");
t.start();
try{
Thread.sleep(40);
}catch(InterruptedException e) { }
t.interrupt();
System.out.println(t.isInterrupted()+" implies was interrupted in between");
try
{
Thread.sleep(200);
}catch(InterruptedException e) {}
}
}
Some where in Khalid i read that we can use statement of the form obj.make().make();
It seems i am missing some thing
So please anyone out there help me
Neelkanthan Keshavan
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keshava,
t.getName().isInterrupted()
The Compiler sees this as :-
Note that getName returns a String.
t.getName()---> (returns a String Object).isInterrupted()
you are calling isInterrupted() on the String!
String class does not have isInterrupted() method
Hence the compile Time Error.
interruption.java:8: Method isInterrupted() not found in class java.lang.Class.

------------------
Pravin R Panicker
Sun Certified Java Programmer
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic