Exemple #1
1
 public static void main(String[] args) {
   MyThread mt = new MyThread();
   Thread t1 = new Thread(mt, "AAAA");
   Thread t2 = new Thread(mt, "BBBB");
   Thread t3 = new Thread(mt, "CCCC");
   t1.setPriority(Thread.MAX_PRIORITY);
   t2.setPriority(Thread.NORM_PRIORITY);
   t3.setPriority(Thread.MIN_PRIORITY);
   t1.start();
   t2.start();
   t3.start();
   mt.run();
 }
Exemple #2
0
 public static void main(String[] args) {
   inst = new SyncTest();
   MyThread t1 = inst.new MyThread(true);
   MyThread t2 = inst.new MyThread(false);
   t1.start();
   t2.start();
 }
Exemple #3
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (!mThread.isAlive()) {
     mThread = new MyThread(holder);
   }
   mThread.start();
 }
 public static void main(String[] args) {
   System.out.println("main:" + Thread.currentThread().getName());
   for (int i = 0; i < 10; i++) {
     MyThread myThread = new MyThread();
     myThread.start();
   }
 }
Exemple #5
0
 public static void main(String a[]) throws Exception {
   t.start();
   for (int i = 0; i < 10; i++) {
     t.join();
     System.out.println(message + i);
   }
 }
 private void startThread() {
   if (thread == null) {
     thread = new MyThread();
     thread.setName(threadName);
     thread.setDaemon(true);
     thread.timer = this;
     thread.start();
   }
 }
  private void startPlaying() {
    mMediaPlayer.start(); // 播放视频

    if (updateProgressBarThread != null) {
      updateProgressBarThread.working = false;
      updateProgressBarThread = null;
    }
    updateProgressBarThread = new MyThread();
    updateProgressBarThread.start();
  }
 public static boolean start() {
   if (false == isThreadStart) {
     isThreadStart = true;
     mThread = new MyThread();
     Log.i(TAG, "LL start >> mThread:" + mThread);
     mThread.setDaemon(true);
     mThread.start();
   }
   return isThreadStart;
 }
Exemple #9
0
 public static void main(String[] args) {
   try {
     MyThread thread = new MyThread();
     thread.start();
     Thread.sleep(1000);
     thread.suspend();
     System.out.println("main end!");
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 public static void main(String[] args) {
   ThreadInterruptDemo test = new ThreadInterruptDemo();
   MyThread thread = test.new MyThread();
   thread.start();
   try {
     Thread.currentThread().sleep(2000);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   thread.interrupt();
 }
Exemple #11
0
 public static void main(String[] args) {
   MyThread mt = new MyThread();
   Thread t = new Thread(mt, "interrupt");
   t.start();
   try {
     Thread.sleep(12);
   } catch (Exception e) {
   }
   t.interrupt();
   mt.run();
 }
Exemple #12
0
 public static void main(String[] args) {
   MyThread mt = new MyThread();
   Thread t = new Thread(mt, "Join");
   t.start();
   try {
     t.join();
     mt.run();
     // t.join();
   } catch (Exception e) {
   }
 }
  public void test() throws IOException {
    fin2 = new FileInputStream(f);
    channel2 = fin2.getChannel();
    bb = new BigByteBuffer2(channel2, FileChannel.MapMode.READ_ONLY, 1024 * 8);
    MyThread th = new MyThread("T1:");
    th.start();
    MyThread th2 = new MyThread("T2: ");
    th2.start();

    System.out.println("Fin de la prueba. " + numPruebas + " iteraciones.");
  }
Exemple #14
0
 public static void main(String[] args) {
   // main 스레드에서 스레드를 생성하면
   // 생성된 스레드는 main의 자식 스레드가 된다.
   // 부모 스레드와 동일한 우선 순위를 갖는다.
   MyThread t1 = new MyThread("t1 ==> "); // main 스레드의 자식 스레드이다.
   MyThread t2 = new MyThread("t2 $$ ");
   t1.start();
   t2.start();
   for (int i = 0; i < 100; i++) {
     System.out.println("main:" + i);
   }
 }
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
      boolean retry = true;
      vThread.setRunning(false);
      while (retry) {
        try {
          vThread.join();
          retry = false;
        } catch (InterruptedException e) {

        }
      }
    }
  public static void StartUnloadingParallel(int SessNo)
      throws IOException, InterruptedException, SQLException {
    System.out.println(
        (new StringBuilder("Unloading Files for Session - "))
            .append(SessNo)
            .append(" is Started")
            .toString());
    for (int i = 0; i < totalvalues; i++) {
      int val = i + 1;
      writer =
          new FileWriterWithEncoding(
              new File((String) filename.get(i)), Charset.forName((String) characterset.get(i)));
      mt =
          new MyThread(
              (new StringBuilder("Unload")).append(SessNo).append(val).toString(),
              writer,
              (ResultSet) rs.get(i),
              val,
              (String) fetchsize.get(i),
              (String) rowsep.get(i),
              (String) delim.get(i),
              (String) header.get(i),
              (String) filename.get(i));
      mt.setName((new StringBuilder("Unload")).append(SessNo).append(val).toString());
      mt.start();
      while (checkThreads.check_unload_completion(
              (new StringBuilder("Unload")).append(SessNo).toString(), "N")
          > 3) ;
    }

    checkThreads.check_unload_completion(
        (new StringBuilder("Unload")).append(SessNo).toString(), "Y");
    System.out.println(
        (new StringBuilder("Unloading Files for Session - "))
            .append(SessNo)
            .append(" is Completed")
            .toString());
    System.out.println("Process Completed");
    stmt.close();
    filename = new ArrayList();
    delim = new ArrayList();
    rowsep = new ArrayList();
    characterset = new ArrayList();
    fetchsize = new ArrayList();
    header = new ArrayList();
    rs = new ArrayList();
  }
Exemple #17
0
 public void stop() {
   _thread.stop();
   try {
     _socket.close();
   } catch (Exception e) {
     Logger.error("@ClientMediator.stop error");
   }
   // kill tank
 }
 public static void trigger() {
   syncInterrupt.lock();
   if (allowInterrupt) {
     myThread.interrupt();
   } else {
     triggered = true;
   }
   syncInterrupt.unlock();
 }
Exemple #19
0
 public static void main(String[] args) throws InterruptedException {
   MyThread th1 = new MyThread();
   MyThread th2 = new MyThread();
   th1.setName("1");
   th2.setName("2");
   th1.start();
   th2.start();
   th1.join();
   th2.join();
   System.out.println(sb.toString());
 }
Exemple #20
0
 public ClientMediator(String name, int id, PrintWriter bos, BufferedReader is, Socket socket) {
   super(name + id, null);
   _id = id;
   _socket = socket;
   _writer = bos;
   _reader = is;
   _thread = new MyThread(this);
   _thread.start();
   tellClient("set-id " + _id, 0);
   tellClient("load simple.txt", 0);
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {

    MyThread myThread = new MyThread();
    myThread.start();

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    mIsServiceRunning = true; // set service running status = true

    // Toast.makeText(this, "Congrats! TiTi Service Started", Toast.LENGTH_LONG).show();
    // We need to return if we want to handle this service explicitly.

    // notification("TiTi","TiTi@Work",2323,new Intent(getApplicationContext(),MainActivity.class));

    return START_STICKY;
  }
Exemple #22
0
  public static void main(String[] args) {

    MyThread thread1 = new MyThread();
    MyThread2 thread2 = new MyThread2();

    Thread myThread2 = new Thread(thread2, "ganka");

    thread1.setThread2(thread2);

    thread1.start();
    myThread2.start();

    try {
      Thread.sleep(4000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    System.out.println("in main method");
  }
 @Override
 protected void onDestroy() {
   updateProgressBarThread.working = false;
   stopService(mFloatingWindow);
   this.unregisterReceiver(mControllerReceiver);
   if (this.mMediaPlayer != null) {
     this.mMediaPlayer.release();
     mMediaPlayer = null;
   }
   mHandler.removeMessages(MyHandler.UPD_VIDEO_PROCESSBAR);
   mFloatingWindow = null;
   super.onDestroy();
 }
  public static void main(String[] argv) throws Exception {
    mbean = newPlatformMXBeanProxy(server, THREAD_MXBEAN_NAME, ThreadMXBean.class);

    if (!mbean.isSynchronizerUsageSupported()) {
      System.out.println("Monitoring of synchronizer usage not supported");
      return;
    }

    thread.setDaemon(true);
    thread.start();

    // wait until myThread acquires mutex and lock owner is set.
    while (!(mutex.isLocked() && mutex.getLockOwner() == thread)) {
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }

    long[] ids = new long[] {thread.getId()};

    // validate the local access
    ThreadInfo[] infos = getThreadMXBean().getThreadInfo(ids, true, true);
    if (infos.length != 1) {
      throw new RuntimeException(
          "Returned ThreadInfo[] of length=" + infos.length + ". Expected to be 1.");
    }
    thread.checkThreadInfo(infos[0]);

    // validate the remote access
    infos = mbean.getThreadInfo(ids, true, true);
    if (infos.length != 1) {
      throw new RuntimeException(
          "Returned ThreadInfo[] of length=" + infos.length + ". Expected to be 1.");
    }
    thread.checkThreadInfo(infos[0]);

    boolean found = false;
    infos = mbean.dumpAllThreads(true, true);
    for (ThreadInfo ti : infos) {
      if (ti.getThreadId() == thread.getId()) {
        thread.checkThreadInfo(ti);
        found = true;
      }
    }

    if (!found) {
      throw new RuntimeException("No ThreadInfo found for MyThread");
    }

    System.out.println("Test passed");
  }
  public void testConcurrentJoinsAndLeaves() throws Exception {
    for (int i = 0; i < threads.length; i++) {
      threads[i] = new MyThread(i, barrier);
      threads[i].start();
    }

    barrier.await(); // causes all threads to call Channel.connect()

    // coordinator attempts to get complete view within 50 (5*10) seconds
    int min = NUM, max = 0;
    for (int i = 0; i < 20; i++) {
      for (MyThread thread : threads) {
        JChannel ch = thread.getChannel();
        View view = ch.getView();
        if (view != null) {
          int size = view.size();
          min = Math.min(size, NUM);
          max = Math.max(size, max);
        }
      }

      if (min >= NUM && max >= NUM) break;
      System.out.println("min=" + min + ", max=" + max);
      Util.sleep(2000);
    }

    System.out.println("reached " + NUM + " members: min=" + min + ", max=" + max);
    assert min >= NUM && max >= NUM : "min=" + min + ", max=" + max + ", expected: " + NUM;

    System.out.println("Starting the disconnect phase");

    for (int i = 0; i < threads.length; i++) {
      MyThread thread = threads[i];
      System.out.print("disconnecting " + thread.getName());
      thread.disconnect();
      System.out.println(" OK");
    }
  }
Exemple #26
0
 public final Result call(Request request) throws Throwable {
   String input = request.getInputText();
   int firstSpacePos = input.indexOf(' ');
   try {
     int number = -1;
     if (firstSpacePos != -1) {
       number = Integer.parseInt(input.substring(0, firstSpacePos));
     } else {
       number = Integer.parseInt(input);
     }
     Log.log_10000(input, number);
     boolean odd = number % 2 == 0;
     boolean thousands = number > 1000;
     long squareNumber = (long) (number * number);
     MyThread thread = new MyThread();
     thread.start();
     Log.log_10002(odd, new Boolean(thousands), squareNumber, thread.toString(), new Date());
   } catch (NumberFormatException nfe) {
     Log.log_10001(nfe);
     return new InvalidNumberResult();
   }
   return new SuccessfulResult();
 }
Exemple #27
0
  public static void main(String[] args) {
    DeadlockRisk dead = new DeadlockRisk();
    MyThread t1 = new MyThread(dead, 1, 2);
    MyThread t2 = new MyThread(dead, 3, 4);
    MyThread t3 = new MyThread(dead, 5, 6);
    MyThread t4 = new MyThread(dead, 7, 8);

    t1.start();
    t2.start();
    t3.start();
    t4.start();

    //		read():Thread-0获取了resourceA的锁!
    //		read():Thread-0获取了resourceB的锁!
    //		write():Thread-0获取了resourceA的锁!
    //		read():Thread-1获取了resourceA的锁!
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (FloatingService.bLock) {
      return false;
    }

    updateProgressBarThread.working = false;
    if (keyCode == KeyEvent.KEYCODE_BACK) {
      this.finish();
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
      // 监控/拦截菜单键
    } else if (keyCode == KeyEvent.KEYCODE_HOME) {
      // 由于Home键为系统键,此处不能捕获,需要重写onAttachedToWindow()

    }
    return super.onKeyDown(keyCode, event);
  }
Exemple #29
0
 private void myStartService() {
   mBtAdapter = BluetoothAdapter.getDefaultAdapter();
   if (mBtAdapter == null) {
     sendToast("No Bluetooth device found on your device!");
     mBtFlag = false;
     return;
   }
   if (!mBtAdapter.isEnabled()) {
     mBtFlag = false;
     sendToast("Opening the bluetooth");
     mBtAdapter.enable();
   }
   mBtAdapter = BluetoothAdapter.getDefaultAdapter();
   sendToast("Start searching!!");
   threadFlag = true;
   mThread = new MyThread();
   mThread.start();
   registerReceiver(new ReconnectReceiver(), new IntentFilter("reconnect"));
 }
Exemple #30
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    MyThread m1 = new MyThread();
    //        m1.setName("10번");
    //        System.out.println(m1.getName());
    //        System.out.println(m1.getPriority());

    MyThread m2 = new MyThread();
    MyThread m3 = new MyThread();

    m1.start();
    m2.start();
    m3.start();
  }