📄 runnablethreaddemo.java
字号:
// Chapter 7, Listing 2
public class RunnableThreadDemo implements java.lang.Runnable
{
// Run method is executed when thread first started
public void run()
{
System.out.println ("I am an instance of the java.lang.Runnable interface");
}
// Main method to create and start threads
public static void main(String args[])
{
System.out.println ("Creating runnable object");
// Create runnable object
Runnable run = new RunnableThreadDemo();
// Create a thread, and pass the runnable object
System.out.println ("Creating first thread");
Thread t1 = new Thread (run);
// Create a second thread, and pass the runnable object
System.out.println ("Creating second thread");
Thread t2 = new Thread (run);
// Start both threads
System.out.println ("Starting both threads");
t1.start(); t2.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -