[Java] Thread
时间:2010-09-10 来源:web_surf
- Documents
- Reference
http://cupi2.uniandes.edu.co/site/images/recursos/javadoc/j2se/1.5.0/docs/api/java/lang/Thread.html
- Samples
- http://walsh.javaeye.com/blog/220212
- http://www.ctba.cn/blog/entry/1475
- http://walsh.javaeye.com/blog/220212
- xxx
- Reference
- Use Thread
class MyThread extends Thread
{
private int m_keeps;
public MyThread(int keeps)
{
m_keeps = keeps;
}
public void run()
{
while(true)
{
try
{
System.out.println(":" + new Date(System.currentTimeMillis()));
Thread.sleep(pauseTime);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
static public void main(String args[])
{
MyThread thread = new MyThread(10000);
thread.start();
}
}
- Use Runnable
class MyRunnable extends Runnable
{
private int m_keeps;
public MyRunnable(int keeps)
{
m_keeps = keeps;
}
public void run()
{
while(true)
{
try
{
System.out.println(":" + new Date(System.currentTimeMillis()));
Thread.sleep(pauseTime);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
static public void main(String args[])
{
Thread thread = new Thread(new MyRunnable(10000));
thread.start();
}
}
- Notes:
- You CANNOT modity ui elements directly in thread
- xxx
- You CANNOT modity ui elements directly in thread
- xxx
相关阅读 更多 +