Esempio n. 1
0
    public void run() {
      while (true) {

        synchronized (currentLock) {
          try {
            target.run();

          } catch (Throwable e) {

            DebugLight.printStackTrace(e);

          } finally {

            target = null;

            debug = null;

            currentLock.released = true;

            currentLock.notifyAll();
          }
        }

        if (isInterrupted() || !Thread.currentThread().isDaemon()) {

          break;

        } else {

          synchronized (daemon_threads) {
            last_active_time = SystemTime.getCurrentTime();

            if (last_active_time < last_timeout_check
                || last_active_time - last_timeout_check > THREAD_TIMEOUT_CHECK_PERIOD) {

              last_timeout_check = last_active_time;

              while (daemon_threads.size() > 0 && daemon_threads.size() > MIN_RETAINED) {

                threadWrapper thread = (threadWrapper) daemon_threads.getFirst();

                long thread_time = thread.last_active_time;

                if (last_active_time < thread_time
                    || last_active_time - thread_time > THREAD_TIMEOUT) {

                  daemon_threads.removeFirst();

                  thread.retire();

                } else {

                  break;
                }
              }
            }

            if (daemon_threads.size() >= MAX_RETAINED) {

              return;
            }

            daemon_threads.addLast(this);

            setName("AEThread2:parked[" + daemon_threads.size() + "]");

            // System.out.println( "AEThread2: queue=" + daemon_threads.size() + ",creates=" +
            // total_creates + ",starts=" + total_starts );
          }

          sem.reserve();

          if (target == null) {

            break;
          }
        }
      }
    }
Esempio n. 2
0
  private TableCellRefresher() {
    runnable =
        new AERunnable() {
          public void runSupport() {
            try {
              Map<TableCell, TableColumn> cellsCopy;
              synchronized (mapCellsToColumn) {
                cellsCopy = new HashMap<TableCell, TableColumn>(mapCellsToColumn);
                mapCellsToColumn.clear();
              }

              for (TableCell cell : cellsCopy.keySet()) {
                TableColumn column = (TableColumn) cellsCopy.get(cell);

                try {
                  // cc.cell.invalidate();
                  if (column instanceof TableCellRefreshListener) {
                    ((TableCellRefreshListener) column).refresh(cell);
                  } else if (column instanceof TableColumnImpl) {
                    List<TableCellRefreshListener> listeners =
                        ((TableColumnImpl) column).getCellRefreshListeners();
                    for (TableCellRefreshListener listener : listeners) {
                      listener.refresh(cell);
                    }
                  }

                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            } finally {
              inProgress = false;
            }
          }
        };

    refresher =
        new AEThread2("Cell Refresher", true) {
          public void run() {
            try {

              iterationNumber = 0;

              while (true) {

                if (mapCellsToColumn.size() > 0 && !inProgress) {
                  inProgress = true;
                  Utils.execSWTThread(runnable);
                }

                Thread.sleep(200);

                iterationNumber++;
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };

    refresher.start();
  }