“Setzen Sie Timeout Java” Code-Antworten

JavaScript setTimeout


 setTimeout(function(){ alert("Hello"); }, 3000);
 
Bald Eagle

Java setTimeout

Try :

public static void setTimeout(Runnable runnable, int delay){
    new Thread(() -> {
        try {
            Thread.sleep(delay);
            runnable.run();
        }
        catch (Exception e){
            System.err.println(e);
        }
    }).start();
}

To called with lambda exception:
setTimeout(() -> System.out.println("test"), 1000);
serge kalaga

Java Timeout

 ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); 
 final Future handler = executor.submit(new Callable(){ ... });
 executor.schedule(new Runnable(){
     public void run(){
         handler.cancel();
     }      
 }, 10000, TimeUnit.MILLISECONDS);
Cheerful Crayfish

Setzen Sie Timeout Java

public static void setTimeout(Runnable runnable, int delay) {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); 
    executor.schedule(new Runnable(){
        public void run() {
            runnable.run();
        }
    }, delay, TimeUnit.MILLISECONDS);
}

// Example
setTimeout(()->{
	System.out.println("Hello World")
},1000);
Mr Fast

Ähnliche Antworten wie “Setzen Sie Timeout Java”

Fragen ähnlich wie “Setzen Sie Timeout Java”

Weitere verwandte Antworten zu “Setzen Sie Timeout Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen