Package java.util.concurrent

Examples of java.util.concurrent.ExecutorService


        });
        future.get((connectTimeoutMillis + readTimeoutMillis), TimeUnit.MILLISECONDS);
    }
 
  public void connectToServer() throws Exception {   
    ExecutorService executor = Executors.newSingleThreadExecutor();   
        Future<Boolean> future = executor.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
              _services = ClientFactory.createCoreServiceClient(_url.toString());
        _session = _services.adminLogin(_user, _password);
        return Boolean.TRUE;
            }
View Full Code Here


    DozerField dozerField = mock(DozerField.class);
    when(dozerField.getName()).thenReturn("");
    fieldMap.setSrcField(dozerField);
    fieldMap.setDestField(dozerField);

    ExecutorService executorService = Executors.newFixedThreadPool(10);
    List<Callable<Object>> callables = new ArrayList<Callable<Object>>();
    for (int i=0; i < 30; i++) {
      callables.add(new Callable<Object>() {
        public Object call() throws Exception {
          return fieldMap.getSrcPropertyDescriptor(String.class);
        }
      });
    }

    executorService.invokeAll(callables);
    Thread.sleep(1000);
    executorService.shutdown();
  }
View Full Code Here

  }

  @Test
  public void shouldInitializeOnce() throws Exception {
    final CallTrackingMapper mapper = new CallTrackingMapper();
    ExecutorService executorService = Executors.newFixedThreadPool(10);

    final CountDownLatch latch = new CountDownLatch(THREAD_COUNT);

    HashSet<Callable<Object>> callables = new HashSet<Callable<Object>>();

    for (int i = 0; i < THREAD_COUNT; i++) {
      callables.add(new Callable<Object>() {
        public Object call() throws Exception {
          latch.countDown();
          latch.await();
          Mapper processor = mapper.getMappingProcessor();
          assertNotNull(processor);
          return null;
        }
      });
    }
    executorService.invokeAll(callables);
    assertEquals(1, mapper.getCalls());
    assertTrue(exceptions.isEmpty());
  }
View Full Code Here

        this.nthreads = nthreads;
    }

    @Override
    public void run(final TestResult result) {
        final ExecutorService exec = Executors.newFixedThreadPool(nthreads);
        final Enumeration<Test> tests = tests();
        while(tests.hasMoreElements()) {
            final Test test = tests.nextElement();
            exec.execute(new Runnable() {
                public void run() {
                    try {
                        test.run(result);
                    } catch (Throwable e) {
                        e.printStackTrace();
View Full Code Here

        InetSocketAddress sockaddr = new InetSocketAddress(addr, port);
        servSocket.bind(sockaddr);
    }

    public void run() {
        final ExecutorService execPool = this.execPool;
        final TransferRequestListener handler = this.handler;
        try {
            while(true) {
                SocketChannel channel = serverChannel.accept();
                execPool.execute(new RequestHandler(channel, handler));
            }
        } catch (ClosedByInterruptException interrupted) {
            if(LOG.isDebugEnabled()) {
                LOG.debug("Avoidable interrupt happened (Normal case): " + interrupted.getMessage());
            }
        } catch (IOException ioe) {
            LOG.error(ioe);
        } catch (Throwable th) {
            LOG.error(th);
        } finally {
            execPool.shutdown();
            try {
                serverChannel.close();
            } catch (IOException ie) {
                if(LOG.isDebugEnabled()) {
                    LOG.debug(PrintUtils.prettyPrintStackTrace(ie, -1));
View Full Code Here

        return add(path, new HttpToEventSourceHandler(handler));
    }

    @Override
    public synchronized NettyWebServer start() {
        ExecutorService exec1 = Executors.newSingleThreadExecutor();
        executorServices.add(exec1);
        ExecutorService exec2 = Executors.newSingleThreadExecutor();
        executorServices.add(exec2);
        bootstrap.setFactory(new NioServerSocketChannelFactory(exec1, exec2, 1));
        channel = bootstrap.bind(socketAddress);
        return this;
    }
View Full Code Here

            }
        }
    }

    public static void main(String[] args) throws Exception {
        ExecutorService webThread = newSingleThreadExecutor();
        final Pusher pusher = new Pusher();

        WebServer webServer = createWebServer(webThread, 9876)
                .add("/events", new EventSourceHandler() {
                    @Override
View Full Code Here

                    tables.put(shippedId, joinTable);
                }
                return map(contextSeq, dynEnv);
            }
            // threaded execution
            final ExecutorService ex = Executors.newSingleThreadExecutor();
            final Callable<JoinTable> call = new Callable<JoinTable>() {
                public JoinTable call() throws Exception {
                    final JoinTable joinTable = makeJoinTable(contextSeq, dynEnv);
                    if(shippedId != -1) {
                        tables.put(shippedId, joinTable);
                    }
                    return joinTable;
                }
            };
            final Future<JoinTable> future = ex.submit(call);
            final Sequence<? extends Item> mapped;
            try {
                mapped = map(contextSeq, dynEnv, future);
            } catch (InterruptedException e) {
                ex.shutdownNow();
                throw new IllegalStateException(e);
            } catch (ExecutionException e) {
                ex.shutdownNow();
                throw new IllegalStateException(e);
            }
            ex.shutdown(); // REVIEWME is really required?
            return mapped;
        }
View Full Code Here

        return result;
    }

    private static Sequence invokeRequestsInParallel(final List<String> endpoints, final BindingVariable hostVar, final PreparedQueryRequest request, final DynamicContext dynEnv) {
        final int numEndpoints = endpoints.size();
        final ExecutorService ex = ExecutorFactory.newFixedThreadPool(numEndpoints, "parallelRemoteExec");
        final Sequence[] results = new Sequence[numEndpoints];
        //final AtomicReferenceArray<Sequence> resultsRef = new AtomicReferenceArray<Sequence>(results);
        try {
            for(int i = 0; i < numEndpoints; i++) {
                final String endpoint = endpoints.get(i);
                final int at = i;
                Runnable r = new Runnable() {
                    public void run() {
                        final Sequence res;
                        try {
                            res = invokeRequest(endpoint, request);
                        } catch (XQueryException e) {
                            throw new IllegalStateException("An error caused while evaluating CompiledQueryRequest#"
                                    + request.getIdentifier() + " at " + endpoint, e);
                        }
                        results[at] = res;
                    }
                };
                ex.execute(r);
            }
        } finally {
            ExecutorUtils.shutdownAndAwaitTermination(ex);
        }
        assert (ex.isTerminated());
        return new PipelinedSequence(dynEnv, results);
    }
View Full Code Here

        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        assertNotNull(service);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);

        String expectedString = new String("How are you Joe");
        try {
            Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
           
            Response<GreetMeSometimeResponse> response = greeter.greetMeSometimeAsync("Joe");
            while (!response.isDone()) {
                Thread.sleep(100);
            }
            GreetMeSometimeResponse reply = response.get();
            assertNotNull("no response received from service", reply);
            String s = reply.getResponseType();
            assertEquals(expectedString, s);  
        } catch (UndeclaredThrowableException ex) {
            throw (Exception)ex.getCause();
        }
        executor.shutdown();
    }
View Full Code Here

TOP

Related Classes of java.util.concurrent.ExecutorService

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.