标签:style blog io ar color os 使用 sp java
一、如何启动一个新的线程
1 public class MyRunnable implements Runnable{
2 public void run(){
3 System.ou.println("这里放上的是需要执行的代码片段"):
4 }
5 }
1 Runnable runnable = new MyRunnable();
2 Thread myThread = new Thread(runnable);
3 myThread.start();
1 try{
2 Thread.sleep(2000);
3 }catch(InterruptedException ex){
4 ex.printStackTrace();
5 }
1 public sychronized void increment(){
2 int i = balance;
3 balance = i+1;
4 }
1 public void increment(){
2 int i = balance;
3 sychronized(this){
4 balance = i+1;
5 }
6 }
标签:style blog io ar color os 使用 sp java
原文地址:http://www.cnblogs.com/KevinHelloWorld/p/4109041.html