All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.frontend2.impl.FutureTest Maven / Gradle / Ivy

Go to download

Create a webserver with this library in just 3 lines of code. just register your HttpRequestListener and it feeds you a FrontendSocket that you write HttpResponses to

There is a newer version: 2.1.1
Show newest version
package org.webpieces.frontend2.impl;

import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

	public class FutureTest {
		
		private Executor exec = Executors.newFixedThreadPool(10);
		
		public static void main(String[] args) {
			new FutureTest().start();
		}
		
		
		private void start() {
			CompletableFuture f = startProcess(5);
			
			f.cancel(false);
		}
	
	
		private CompletableFuture startProcess(int i) {
			CompletableFuture future1 = remoteCall(5);
			CompletableFuture future2 = future1.thenCompose(s -> remoteCall(10));
			CompletableFuture future3 = future2.thenCompose(s -> remoteCall(15));
			CompletableFuture future4 = future3.thenCompose(s -> remoteCall(20));
			return future4;
		}
	
	
		public CompletableFuture remoteCall(int value) {
			CompletableFuture future = new CompletableFuture();
			exec.execute(new Runnable() {
				@Override
				public void run() {
					System.out.println("RUnning task="+value);
					
					try {
						Thread.sleep(5000);
						future.complete(value+4);
					} catch (InterruptedException e) {
						future.completeExceptionally(e);
					}
					
				}
			});
			
			return future;
		}
	
	}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy