Exemplo n.º 1
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();
 }
Exemplo n.º 2
0
  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.");
  }
Exemplo n.º 3
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());
 }
Exemplo n.º 4
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);
   }
 }
Exemplo n.º 5
0
 public static void main(String[] args) {
   Account account = new Account();
   MyThread thread1 = new MyThread(100, 10, account);
   MyThread thread2 = new MyThread(-100, 10, account);
   thread1.start();
   thread2.start();
   try {
     thread1.join();
     thread2.join();
   } catch (Exception e) {
     e.printStackTrace();
   }
   System.out.println(account.getBalance());
 }
Exemplo n.º 6
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();
  }
Exemplo n.º 7
0
 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();
   }
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   if (!mThread.isAlive()) {
     mThread = new MyThread(holder);
   }
   mThread.start();
 }
Exemplo n.º 10
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的锁!
  }
Exemplo n.º 11
0
  public static void main(String[] args) {
    // beginn main Thread
    System.out.println("Main Thread gestartet");

    // Thread Objekt erzeugen
    MyThread t = new MyThread("A", 100);
    MyThread t2 = new MyThread("B", 300);
    MyThread t3 = new MyThread("C", 500);

    // Thread nebenlaeufig starten
    t.start();
    t2.start();
    t3.start();

    // Ende main-Thread
    System.out.println("Main Thread zuende");
  }
Exemplo n.º 12
0
 private void startThread() {
   if (thread == null) {
     thread = new MyThread();
     thread.setName(threadName);
     thread.setDaemon(true);
     thread.timer = this;
     thread.start();
   }
 }
Exemplo n.º 13
0
  private void startPlaying() {
    mMediaPlayer.start(); // 播放视频

    if (updateProgressBarThread != null) {
      updateProgressBarThread.working = false;
      updateProgressBarThread = null;
    }
    updateProgressBarThread = new MyThread();
    updateProgressBarThread.start();
  }
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
 public static void main(String[] args) throws InterruptedException {
   MyThread thread1 = new MyThread();
   MyThread thread2 = new MyThread();
   thread1.start();
   thread2.start();
   thread1.join();
   thread2.join();
   System.out.println(Counter.getCounter());
   System.out.println("Hellow to you too!");
   MyRunnable runnable = new MyRunnable(4, 2);
   Thread thread3 = new Thread(runnable);
   thread3.start();
   System.out.println("LOL I'm Not I'm a MAIN Thread!");
   ThreadVisibility thread4 = new ThreadVisibility();
   thread4.start();
   Thread.sleep(1000);
   thread4.setToFalse();
   System.out.println("keepRunning is false");
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
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();
   }
 }
Exemplo n.º 18
0
 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();
 }
Exemplo n.º 19
0
  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");
  }
Exemplo n.º 20
0
  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();
  }
Exemplo n.º 21
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"));
 }
  @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;
  }
Exemplo n.º 23
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");
  }
  public static void start() {
    myThread.start();

    new Thread() {

      @Override
      public void run() {

        final String orgName = Thread.currentThread().getName();
        Thread.currentThread().setName(orgName + " - MessageDownloader - decrease pubmsg");

        while (!Main.shutdown) {

          try {
            sleep(1000 * 60 * 60);
          } catch (InterruptedException ex) {
            Logger.getLogger(MessageDownloader.class.getName()).log(Level.SEVERE, null, ex);
          }

          if (MessageDownloader.publicMsgsLoaded > 50) {
            Log.put(
                "not decreasing pubmsgs, msgs to verify: " + MessageDownloader.publicMsgsLoaded,
                100);
            continue;
          }

          publicMsgsLoaded -= Math.ceil(Settings.MAXPUBLICMSGS / 60) + 1;
          if (publicMsgsLoaded < 0) {
            publicMsgsLoaded = 0;
          }

          if (publicMsgsLoaded != 0) {
            System.out.println("Decresed pubmsgs: " + publicMsgsLoaded);
          }
        }
      }
    }.start();
  }
Exemplo n.º 25
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();
 }
Exemplo n.º 26
0
 public static void main(String[] args) {
   MyThread zhangfei = new MyThread("张飞");
   MyThread wangfei = new MyThread("王菲");
   zhangfei.start();
   wangfei.start();
 }
  private static String convertStreamToString(
      InputStream is, boolean isGzipEnabled, File file, Context con) throws IOException {
    InputStream cleanedIs = is;
    if (isGzipEnabled) {
      cleanedIs = new GZIPInputStream(is);
    }
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(file);
      byte[] buffer = new byte[1024];
      int len1 = 0;
      final String path = "DL" + file.getAbsolutePath();
      final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(con);
      final Editor ed = sp.edit();
      donwloaded = 0;

      class MyThread extends Thread {

        volatile boolean finished = false;

        public void stopMe() {
          finished = true;
        }

        @Override
        public void run() {
          while (!finished) {
            ed.putLong(path, donwloaded);
            ed.commit();
            try {
              Thread.sleep(100);

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

      final MyThread thread = new MyThread();
      thread.start();
      while ((len1 = cleanedIs.read(buffer)) != -1) {
        fos.write(buffer, 0, len1);
        donwloaded += len1;
      }
      ed.putLong(path, donwloaded);
      ed.commit();
      thread.stopMe();

      fos.flush();
    } finally {
      if (fos != null) {
        fos.close();
      }
      cleanedIs.close();
      if (isGzipEnabled) {
        is.close();
      }
    }

    return "";
  }
Exemplo n.º 28
0
 public static void main(String args[]) {
   MyThread t = new MyThread();
   t.start();
   t.start();
 }
Exemplo n.º 29
0
 public static void main(String[] args) throws InterruptedException {
   MyThread myThread = new MyThread("myThread");
   myThread.start();
 }
Exemplo n.º 30
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   vThread.setRunning(true);
   vThread.start();
 }