Package java.util.concurrent

Examples of java.util.concurrent.ExecutorCompletionService.submit()


            // Execute collection asynchronously (TODO: cache pool usage could be
            // improved)
            final ExecutorService cachePool = Executors.newCachedThreadPool();
            final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
            final Future<String> future = ecs.submit(new Callable<String>() {

                public String call() throws Exception {
                    return AccessController.doPrivileged(new PrivilegedAction<String>() {
                        public String run() {
                            return newClient.toString();
View Full Code Here


        final DiscoveryManager newClient = Proxies.newClient(EXPORT_NAME, address, getClass().getClassLoader(), DiscoveryManager.class);

        // Execute collection asynchronously (TODO: cache pool usage could be improved)
        final ExecutorService cachePool = Executors.newCachedThreadPool(RemoteDiscoveryImpl.threadFactory);
        final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(cachePool);
        final Future<String> future = ecs.submit(new Callable<String>() {

            public String call() throws Exception {
                return AccessController.doPrivileged(new PrivilegedAction<String>() {
                    public String run() {
                        return newClient.ping(667) == 667 ? "OK" : null;
View Full Code Here

        // so lets try that ...
        final R newClient = Proxies.newClient(name, address, remote);

        // Execute collection asynchronously
        final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(Executors.newCachedThreadPool());
        ecs.submit(new Callable<String>() {

            public String call() throws Exception {
                return newClient.toString();
            }
        });
View Full Code Here

    public static void main(String[] args) {

        // Execute collection asynchronously
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        final ExecutorCompletionService<String> ecs = new ExecutorCompletionService(newCachedThreadPool);
        Future<String> submit = ecs.submit(new Callable<String>() {

            public String call() {
                try {
                    Thread.sleep(1012331872);
                } catch (InterruptedException e) {
View Full Code Here

               Bucket bucket = unmarshallBucket(binaryStream);
               bucket.setBucketId(bucketId);
               expiredBuckets.add(bucket);
               if (expiredBuckets.size() == BATCH_SIZE) {
                  ++tasksScheduled;
                  ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
                  expiredBuckets = new ArrayList<Bucket>(BATCH_SIZE);
               }
            } else {
               if (log.isTraceEnabled()) {
                  log.tracef("Could not acquire write lock for %s, this won't be purged even though it has expired elements", bucketId);
View Full Code Here

            tasksCompleted += unlockCompleted(ecs, false); // cannot throw InterruptedException
         }

         if (!expiredBuckets.isEmpty()) {
            ++tasksScheduled;
            ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
         }
         // wait until all tasks have completed
         try {
            while (tasksCompleted < tasksScheduled) {
               tasksCompleted += unlockCompleted(ecs, true);
View Full Code Here

               Bucket bucket = unmarshallBucket(binaryStream);
               bucket.setBucketId(bucketId);
               expiredBuckets.add(bucket);
               if (expiredBuckets.size() == BATCH_SIZE) {
                  ++tasksScheduled;
                  ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
                  expiredBuckets = new ArrayList<Bucket>(BATCH_SIZE);
               }
            } else {
               if (log.isTraceEnabled()) {
                  log.tracef("Could not acquire write lock for %s, this won't be purged even though it has expired elements", bucketId);
View Full Code Here

            tasksCompleted += unlockCompleted(ecs, false); // cannot throw InterruptedException
         }

         if (!expiredBuckets.isEmpty()) {
            ++tasksScheduled;
            ecs.submit(new BucketPurger(expiredBuckets, task, ctx.getMarshaller(), conn, emptyBuckets));
         }
         // wait until all tasks have completed
         try {
            while (tasksCompleted < tasksScheduled) {
               tasksCompleted += unlockCompleted(ecs, true);
View Full Code Here

            int count = 0;
            debug("Number of execution threads: %s", nThreads);

            try {
                for (final String file : listSelectedFiles()) {
                    completionService.submit(new Runnable() {
                        public void run() {
                            Document document = documentFactory.createDocuments(file);
                            debug("Selected file: %s [header style: %s]", document.getFile(), document.getHeaderDefinition());
                            if (document.isNotSupported()) {
                                warn("Unknown file extension: %s", document.getFile());
View Full Code Here

            int count = 0;
            debug("Number of execution threads: %s", nThreads);

            try {
                for (final String file : listSelectedFiles()) {
                    completionService.submit(new Runnable() {
                        public void run() {
                            Document document = documentFactory.createDocuments(file);
                            debug("Selected file: %s [header style: %s]", document.getFile(), document.getHeaderDefinition());
                            if (document.isNotSupported()) {
                                warn("Unknown file extension: %s", document.getFile());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.