Package java.util.concurrent

Examples of java.util.concurrent.ExecutorService


        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);

        final String expectedString = new String("How are you Joe");
         
        class Poller extends Thread {
            Response<GreetMeSometimeResponse> response;
            int tid;
           
            Poller(Response<GreetMeSometimeResponse> r, int t) {
                response = r;
                tid = t;
            }
            public void run() {
                if (tid % 2 > 0) {
                    while (!response.isDone()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                            // ignore
                        }
                    }
                }
                GreetMeSometimeResponse reply = null;
                try {
                    reply = response.get();
                } catch (Exception ex) {
                    fail("Poller " + tid + " failed with " + ex);
                }
                assertNotNull("Poller " + tid + ": no response received from service", reply);
                String s = reply.getResponseType();
                assertEquals(expectedString, s);  
            }
        }
       
        Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
        Response<GreetMeSometimeResponse> response = greeter.greetMeSometimeAsync("Joe");
       
        Poller[] pollers = new Poller[4];
        for (int i = 0; i < pollers.length; i++) {
            pollers[i] = new Poller(response, i);
        }
        for (Poller p : pollers) {           
            p.start();
        }
       
        for (Poller p : pollers) {
            p.join();
        }
       
        executor.shutdown();   
    }
View Full Code Here


    public void testAsyncCallWithHandler() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);
       
        MyHandler h = new MyHandler();
        MyHandler.invocationCount = 0;

        String expectedString = new String("How are you Joe");
        try {
            Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
            Future<?> f = greeter.greetMeSometimeAsync("Joe", h);
            int i = 0;
            while (!f.isDone() && i < 20) {
                Thread.sleep(100);
                i++;
            }
            assertEquals("callback was not executed or did not return the expected result",
                         expectedString, h.getReplyBuffer());
        } catch (UndeclaredThrowableException ex) {
            throw (Exception)ex.getCause();
        }
        assertEquals(1, MyHandler.invocationCount);      
        executor.shutdown();
    }
View Full Code Here

    public void testAsyncCallWithHandlerAndMultipleClients() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);
       
        final MyHandler h = new MyHandler();
        MyHandler.invocationCount = 0;

        final String expectedString = new String("How are you Joe");
       
        class Poller extends Thread {
            Future<?> future;
            int tid;
           
            Poller(Future<?> f, int t) {
                future = f;
                tid = t;
            }
            public void run() {
                if (tid % 2 > 0) {
                    while (!future.isDone()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                            // ignore
                        }
                    }
                }
                try {
                    future.get();
                } catch (Exception ex) {
                    fail("Poller " + tid + " failed with " + ex);
                }
                assertEquals("callback was not executed or did not return the expected result",
                             expectedString, h.getReplyBuffer());
            }
        }
       
        Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
        Future<?> f = greeter.greetMeSometimeAsync("Joe", h);
       
        Poller[] pollers = new Poller[4];
        for (int i = 0; i < pollers.length; i++) {
            pollers[i] = new Poller(f, i);
        }
        for (Poller p : pollers) {           
            p.start();
        }
       
        for (Poller p : pollers) {
            p.join();
        }
        assertEquals(1, MyHandler.invocationCount);  
        executor.shutdown();   
    }
View Full Code Here

    public void testFaults() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService ex = Executors.newFixedThreadPool(1);
        service.setExecutor(ex);
        assertNotNull(service);

        String noSuchCodeFault = "NoSuchCodeLitFault";
        String badRecordFault = "BadRecordLitFault";
View Full Code Here

    return SUCCESS;
  }

  private String guessFeedTitle(String url) {
    String title = null;
    ExecutorService service = null;
    try {
      FetchRssDataWorker worker = new FetchRssDataWorker(url);
      service = Executors.newFixedThreadPool(1);
      service.execute(worker);
      service.shutdown();
      service.awaitTermination(5, TimeUnit.SECONDS);
      title = worker.getRssTitle();
      logger.debug("detected RSS title: " + title);
    } catch (Exception e) {
      logger.debug(e);
    } finally {
      if (service != null) {
        try {
          service.shutdown();
        } catch (Exception e) {
          logger.debug(e);
        }
      }
    }
View Full Code Here

      ModuleMetaData conflict = new ModuleMetaData();
      conflict.setName("conflict.war");
      conflict.setUniqueName(SIMPLE_TRIMMED_PATH);
      modsmd.add(conflict);
     
      ExecutorService executor = Executors.newFixedThreadPool(3);
     
      CountDownLatch startLatch = new CountDownLatch(4);
      CountDownLatch finishLatch = new CountDownLatch(3);
     
      DeploymentTask warTask = new DeploymentTask(startLatch, finishLatch, war);
      executor.execute(warTask);
     
      DeploymentTask jarTask = new DeploymentTask(startLatch, finishLatch, jar);
      executor.execute(jarTask);
     
      DeploymentTask appclientTask = new DeploymentTask(startLatch, finishLatch, appClient);
      executor.execute(appclientTask);
     
      startLatch.countDown();
     
      assertTrue(finishLatch.await(5, TimeUnit.SECONDS));
     
View Full Code Here

          callables.add(downloadThread);
        }
        // Loop until all images are downloaded or timeout is reached
        long totalTimeout = DOWNLOAD_TIMEOUT + DOWNLOAD_TIMEOUT_ONE_TILE * tiles.size();
        log.debug("=== total timeout (millis): {}", totalTimeout);
        ExecutorService service = Executors.newFixedThreadPool(DOWNLOAD_MAX_THREADS);
        List<Future<ImageResult>> futures = service.invokeAll(callables, totalTimeout, TimeUnit.MILLISECONDS);
        // determine the pixel bounds of the mosaic
        Bbox pixelBounds = getPixelBounds(tiles);
        // create the images for the mosaic
        List<RenderedImage> images = new ArrayList<RenderedImage>();
        for (Future<ImageResult> future : futures) {
View Full Code Here

        compare(t);
    }

    private void compare(Thread[] t) throws InterruptedException {
    ExecutorService pool =
      Executors.newFixedThreadPool(t.length);
   
        for (Thread ti : t)
            pool.execute(ti);
   
    pool.shutdown();
    pool.awaitTermination(20, TimeUnit.SECONDS);

        for (int i = 0; i < x.size(); ++i)
            assertEquals(x.get(i), output[i], 1e-10);
    }
View Full Code Here

            callables.add(downloadThread);
          }
          // Loop until all images are downloaded or timeout is reached
          long totalTimeout = DOWNLOAD_TIMEOUT + DOWNLOAD_TIMEOUT_ONE_TILE * tiles.size();
          log.debug("=== total timeout (millis): {}", totalTimeout);
          ExecutorService service = Executors.newFixedThreadPool(DOWNLOAD_MAX_THREADS);
          List<Future<ImageResult>> futures = service.invokeAll(callables, totalTimeout,
              TimeUnit.MILLISECONDS);
          // determine the pixel bounds of the mosaic
          Bbox pixelBounds = getPixelBounds(tiles);
          int imageWidth = configurationService.getRasterLayerInfo(getLayerId()).getTileWidth();
          int imageHeight = configurationService.getRasterLayerInfo(getLayerId()).getTileHeight();
View Full Code Here

    executor.setThreadFactory(new ThreadFactoryBuilder()
        .setDaemon(true)
        .setThreadFactory(executor.getThreadFactory())
        .build());

    ExecutorService service = Executors.unconfigurableExecutorService(executor);

    addDelayedShutdownHook(service, terminationTimeout, timeUnit);

    return service;
  }
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.