• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Thread question required

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A implements Runnable {
int i;
public void run () {
try {
thread.sleep(5000);
i= 10;
} catch(InterruptedException e) {}
}
}
public class test {
public static void main (String args[]) {
try {
A a = new A ();
Thread t = new Thread (a);
t.start();
t.join();
int j= a.i;
}catch (Exception e) {}
}
}
E:\l>javac test.java
test.java:5: cannot resolve symbol
symbol : variable t
location: class A
t.sleep(5000);
^
1 error
Can somebody tell me why does it compile fail ?
Thanks !!
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,

Next time, please use the CODE UBB. It will preserve the indentation of your code.

sleep() is a static method of the thread class.
Use Thread.sleep(5000) instead of thread.sleep(5000)

Sheldon
 
PETER CARTER
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Thread.sleep(5000) instead of thread.sleep(5000)


Thanks !!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic