package com.company;
import java.io.Console;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Main {
static boolean isToastShewnLeft = false;
public static void main(String[] args) {
showToastLeft("first", "", "");
showToastLeft("second", "", "");
showToastLeft("third", "", "");
showToastLeft("fourth", "", "");
showToastLeft("fifth", "", "");
}
public static void showToastLeft(final String paramToastString1, final String paramToastString2, final String paramToastString3) {
final long start = System.currentTimeMillis();
ScheduledExecutorService worker1 = Executors.newSingleThreadScheduledExecutor();
ScheduledExecutorService worker2 = Executors.newSingleThreadScheduledExecutor();
if (isToastShewnLeft) {
final Runnable r = new Runnable() {
@SuppressWarnings("StatementWithEmptyBody")
public void run() {
while (isToastShewnLeft) {
}
isToastShewnLeft = true;
//This line does not appear in console output
//I can set a breakpoint on this println and see that it does execute
System.out.println(paramToastString1);
ScheduledExecutorService worker3 = Executors.newSingleThreadScheduledExecutor();
final Runnable r2 = new Runnable() {
public void run() {
isToastShewnLeft = false;
System.out.println(System.currentTimeMillis() - start + " Set toast not shewn");
}
};
worker3.schedule(r2, 5, TimeUnit.SECONDS);
}
};
worker1.schedule(r, 0, TimeUnit.SECONDS);
} else {
isToastShewnLeft = true;
System.out.println(paramToastString1);
final Runnable r2 = new Runnable() {
public void run() {
isToastShewnLeft = false;
System.out.println(System.currentTimeMillis() - start + " Set toast not shewn");
}
};
worker2.schedule(r2, 5, TimeUnit.SECONDS);
}
}
}
/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java -Didea.launcher.port=7543 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14 CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/ericsepich/IdeaProjects/untitled1/out/production/untitled1:/Applications/IntelliJ IDEA 14 CE.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
first
5008 Set toast not shewn
我的目的是在showToastLeft的每個調用之間顯示5秒的文本。執行程序線程使用來自 的println有沒有問題?我使用IntelliJ的想法作爲我的IDE。Executor System.out.println未在控制檯中顯示
我將在我的調試器中發佈一個屏幕截圖,顯示布爾值的值爲true。
感謝您的任何反應....
所以你看到的唯一的輸出是'第一'然後'5008設置烤麪包沒有shewn'? –
正確。 println有可能存在線程問題嗎? – Giuseppe
我做了一個可以粘貼到IntelliJ中的複製粘貼示例。我目前在優勝美地環境中。我認爲JDK版本已發佈。 – Giuseppe