zoukankan      html  css  js  c++  java
  • 理解多线程共享与线程池

    最近在写程序的时候,突然感觉以前对线程的了解太少了。对多线程数据共享和单线程池的概念给弄混了!

    (1)单线程池作用主要是用来调度当前情况下只允许一个线程运行,但是可以压入多个线程,这些线程彼此间应该是无关的,不应该存在数据共享

           参考 http://wawlian.iteye.com/blog/1315256

    (2)多线程数据共享,多个线程共享数据

          参考 http://java.chinaitlab.com/line/10271.html

                http://blog.csdn.net/com360/article/details/6795060

     (3)多个线程共享数据,但多个线程要串联执行

           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){               

    class t1 extends Thread{      

    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();   

    }

  • 相关阅读:
    UESTC--1267
    HDU--1394
    rvm 安装后的补充工作:source $HOME/.profile
    FFmpeg 初级使用
    Vue 打包部署上线
    阿里云Centos7.6中部署nginx1.16+uwsgi2.0.18+Django2.0.4
    响应式网站设计---Bootstrap
    GitBook简单的使用
    VUE 参数共享问题
    Django之JWT理解及简单应用
  • 原文地址:https://www.cnblogs.com/DreamSea-for-Jimmy/p/3303530.html
Copyright © 2011-2022 走看看