【未解决】docker stack deploy 个别container通过 inprogress 网络访问不正常 问题: docker stack deploy 个别container通过 inprogress 网络访问不正… Read More
Java FutureTask demo 问题: 解决: //FutureTaskTest.java //javac FutureTaskTest.java && java FutureTaskTest import java.util.concurrent.*; public class FutureTaskTest{ public static void main(String[] argv) throws Exception{ Callable<String> c = ()->{ try{Thread.sleep(1000);}catch(Exception e){} return "hello"; }; FutureTask<String> task = new FutureTask<>(c); new Thread(task).start(); System.out.println("wait for get.."); String ret = task.get(); System.out.println("get() return "+ret); } } ~ 12345678910111213141516171819 //FutureTaskTest.java//javac FutureTaskTest.java && java FutureTaskTest import java.util.concurrent.*; public class FutureTaskTest{ public static void main(String[] argv) throws Exception{ Callable<String> c = ()->{ try{Thread.sleep(1000);}catch(Exception e){} return "hello"; }; FutureTask<String> task = new FutureTask<>(c); new Thread(task).start(); System.out.println("wait for get.."); String ret = task.get(); System.out.println("get() return "+ret); }}~ … Read More
Java Exchanger 基本用法 demo 问题: 解决: //ExchangerTest.java //javac ExchangerTest.java && java ExchangerTest import java.util.concurrent.*; class ExchangerTest{ public static void main(String[] argv){ Exchanger<String> ex = new Exchanger<>(); Thread t1 = new Thread(()->{ try{ String msg = ex.exchange("T1 welcome"); System.out.println("t1 get msg : "+msg); }catch(Exception e){} }); t1.start(); Thread t2 = new Thread(()->{ try{ Thread.sleep(1000); String msg = ex.exchange("T2 welcome"); System.out.println("t2 get msg : "+msg); }catch(Exception e){} }); t2.start(); } } 1234567891011121314151617181920212223242526 //ExchangerTest.java//javac ExchangerTest.java && java ExchangerTest import java.util.concurrent.*; class ExchangerTest{ public static void main(String[] argv){ Exchanger<String> ex = new Exchanger<>(); Thread t1 = new Thread(()->{ try{ String msg = ex.exchange("T1 welcome"); System.out.println("t1 get msg : "+msg); }catch(Exception e){} }); t1.start(); Thread t2 = new Thread(()->{ try{ Thread.sleep(1000); String msg = ex.exchange("T2 welcome"); System.out.println("t2 get msg : "+msg); }catch(Exception e){} }); t2.start(); }} … Read More