Package java.util.concurrent

Examples of java.util.concurrent.FutureTask


    Process p = null;
    try
    {
      p = Runtime.getRuntime().exec(cmd);
      final Process fp = p;
      FutureTask<String> future = new FutureTask(new Callable()
      {

        public String call() throws Exception
        {
          StringBuffer result = new StringBuffer();
          InputStream in = fp.getInputStream();
          int x;
          while ((x = in.read()) != -1)
            result.append((char) x);

          return result.toString();
        }
      });
      executor.execute(future);
      String result = future.get(timeout, TimeUnit.MILLISECONDS);
      return result;

    }
    catch (Exception e)
    {
View Full Code Here


        return response;
    }


    public FutureTask<SResponse> asyncHttp(final Url url, final String jsonData, final RestRequest.Method method) {
        FutureTask<SResponse> getRemoteDataTask = new FutureTask(new Callable<SResponse>() {
            @Override
            public SResponse call() throws Exception {
                return http(url, jsonData, method);
            }
        });
View Full Code Here

                public void run()
                {
                    MemtableManager.instance().submit(cfName_, Memtable.this, cLogCtx);
                }
            };
            flushQueuer = new FutureTask(runnable, null);
        }
View Full Code Here

            warn(bundle, "Error while creating extension", t);
        }
    }

    private void destroyExtension(final Bundle bundle) {
        FutureTask future;
        synchronized (extensions) {
            debug(bundle, "Starting destruction process");
            future = destroying.get(bundle);
            if (future == null) {
                final Extension extension = extensions.remove(bundle);
                if (extension != null) {
                    debug(bundle, "Scheduling extension destruction");
                    future = new FutureTask<Void>(new Runnable() {
                        public void run() {
                            debug(bundle, "Destroying extension");
                            try {
                                extension.destroy();
                            } catch (Exception e) {
                                warn(bundle, "Error while destroying extension", e);
                            } finally {
                                debug(bundle, "Finished destroying extension");
                                synchronized (extensions) {
                                    destroying.remove(bundle);
                                }
                            }
                        }
                    }, null);
                    destroying.put(bundle, future);
                } else {
                    debug(bundle, "Not an extended bundle or destruction of extension already finished");
                }
            } else {
                debug(bundle, "Destruction already scheduled");
            }
        }
        if (future != null) {
            try {
                debug(bundle, "Waiting for extension destruction");
                future.run();
                future.get();
            } catch (Throwable t) {
                warn(bundle, "Error while destroying extension", t);
            }
        }
    }
View Full Code Here

    int count = 0;
      while(count < 1000) {
          count++;
          logger.info("Launching " + count + "-th operation");
          final int c = count;
          FutureTask task = new FutureTask<Object>(
            new Thread() {
              public void run() {
                    Model.getByKey(PersonLongAutoIDModel.class, PERSON_LONGAUTOID_TESLA.id);
                  logger.info("Executed " + c + "-th operation");
                }
            }, null);
          Thread thread = new Thread(task);
          thread.start();
          try {
              task.get(1l, TimeUnit.HOURS);
          } catch (Exception e) {
              e.printStackTrace();
          }  
      }
  }
View Full Code Here

       
        assertEquals(0, this.collector.getEvents().size());
    }

    public void testCollectFromDifferentThreads() throws Exception {
        FutureTask f1 = new FutureTask(new Tester());
        FutureTask f2 = new FutureTask(new Tester());
        Thread t1 = new Thread(f1);
        Thread t2 = new Thread(f2);
       
        t1.start();
        t2.start();
       
        int total1 = 0;
        int total2 = 0;
        try {   
            total1 = (Integer) f1.get();
            total2 = (Integer) f2.get();
        } catch (Exception ex) {
            ex.printStackTrace();
            this.fail("Test failure: " + ex.getMessage());
        }
        assertEquals(0, total1);
View Full Code Here

        assertSame(e2, this.collector.pollEvent());
        assertSame(e3, this.collector.pollEvent());
    }
   
    public void testCollectAndPollFromDifferentThreads() throws Exception {
        FutureTask f1 = new FutureTask(new Producer());
        FutureTask f2 = new FutureTask(new Consumer());
        Thread t1 = new Thread(f1);
        Thread t2 = new Thread(f2);
       
        t1.start();
        t2.start();
       
        try {
            f1.get();
            f2.get();
        } catch (Exception ex) {
            ex.printStackTrace();
            this.fail("Test failure: " + ex.getMessage());
        }
    }
View Full Code Here

       
        assertEquals(0, this.collector.getEvents().size());
    }

    public void testCollectFromDifferentThreads() throws Exception {
        FutureTask f1 = new FutureTask(new Tester());
        FutureTask f2 = new FutureTask(new Tester());
        Thread t1 = new Thread(f1);
        Thread t2 = new Thread(f2);
       
        t1.start();
        t2.start();
       
        try {   
            f1.get();
            f2.get();
        } catch (Exception ex) {
            ex.printStackTrace();
            this.fail("Test failure: " + ex.getMessage());
        }
    }
View Full Code Here

            // failed to create a proxy for it.
            handler = originalHandler;
        }

        cft = new CallbackFutureTask(ic.getAsyncResponseListener(), handler, handlerCL);
        task = new FutureTask(cft);
        executor = ic.getExecutor();
       
        /*
         * TODO review.  We need to save the invocation context so we can set it on the
         * response (or fault) context so the FutureCallback has access to the handler list.
View Full Code Here

                public Message createMessage(Session session) throws JMSException {
                    Message message = endpoint.getBinding().makeJmsMessage(exchange, in, session);
                    message.setJMSReplyTo(replyTo);
                    requestor.setReplyToSelectorHeader(in, message);

                    FutureTask future = null;
                    future = (!msgIdAsCorrId)
                        ? requestor.getReceiveFuture(message.getJMSCorrelationID(), endpoint
                            .getRequestTimeout()) : requestor.getReceiveFuture(callback);

                    futureHolder.set(future);
View Full Code Here

TOP

Related Classes of java.util.concurrent.FutureTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.