如何启动第一个线程完成到第二个线程启动后

时间:2019-06-18 10:09:15

标签: android multithreading thread-safety

我正在使用某种方法,我需要某种方法完成才能启动另一种方法,以便正在使用线程功能,如何先启动一个线程,然后再启动第二个线程?

Thread thread1 = new Thread(new Runnable() {
        @Override
        public void run() {
            try {

                loadIrrigationSourceMaster();
                loadIrrigationMaster();
                loadSeasonMaster();
                loadFactoryMaseter();


            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    thread1.start();

    Thread thread2 = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                loadTransport();
                plantTypeMaster();
                plotOwnerTypeMaster();
                ExitRatoonMaster();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    thread2.start();

1 个答案:

答案 0 :(得分:0)

"ufield943" : "SU\/HI\/14"

以上结果:

  (new Thread(new Runnable() {
        @Override
        public void run() {

            //TODO: fist thread code here 
            Log.w("tag","1");
            (new Thread(new Runnable() {
                @Override
                public void run() {
                       //TODO: second thread code here 
                        Log.w("tag","2");
                }
            })).start();
        }
    })).start();

但是我不认为这是个好主意。只需将其余工作放在第一tag:1 tag:2