最近在寫程序的時候,忽然感受之前對線程的瞭解太少了。對多線程數據共享和單線程池的概念給弄混了!html
(1)單線程池做用主要是用來調度當前狀況下只容許一個線程運行,可是能夠壓入多個線程,這些線程彼此間應該是無關的,不該該存在數據共享java
參考 http://wawlian.iteye.com/blog/1315256多線程
(2)多線程數據共享,多個線程共享數據.net
參考 http://java.chinaitlab.com/line/10271.html線程
http://blog.csdn.net/com360/article/details/6795060htm
(3)多個線程共享數據,但多個線程要串聯執行blog
private static ArrayList<ExcelTable> list = new ArrayList<ExcelTable>();
pivate static volatile int controlInt = 0;排序
public static void teleSegSort(final String filePath,final String splitSign,final int colNum,final int phoneColIndex,final int sortByColIndex,final MsgCallback callback){ get
class t1 extends Thread{ it
public void run() {
if (controlInt==0) {
//list賦值
controlInt = 1; }
};
}
class t2 extends Thread{
public void run() {
boolean isrunning = true;
while(isrunning){
if(controlInt==1){
//對list 排序
controlInt = 2;
isrunning=false; } } } };
class t3 extends Thread{
public void run() {
boolean isrunning = true;
while (isrunning) {
if(controlInt==2){
//list排序後輸出
controlInt = 3; }
}
}
};
controlInt = 0;
new t1().start();
new t2().start();
new t3().start();
}