上一页 1 2 3 4 5 6 7 8 ··· 40 下一页
摘要: 1. 1 public class ListAdd1 { 2 private volatile static List list = new ArrayList(); 3 4 public void add(){ 5 list.add("hello"); 6 } 7 8 public int siz 阅读全文
posted @ 2017-12-01 21:55 黑土白云 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1. 1 public class VolatileNoAtomic extends Thread { 2 private static volatile int count; //volatile具有线程间的变量的可见性不具备原子性 3 4 public void run(){ 5 addCoun 阅读全文
posted @ 2017-12-01 21:43 黑土白云 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 1. 改成static也不行 private static boolean isRunning = true; volatile关键字主要用于线程变量在多个线程之间的可见 1 public class RunThread extends Thread{ 2 private volatile bool 阅读全文
posted @ 2017-12-01 21:22 黑土白云 阅读(266) 评论(0) 推荐(0) 编辑
摘要: 1. 1 public class SyncDubbo2 { 2 static class Sup{ //父类 3 public int i = 10; 4 public synchronized void operSup(){ 5 try{ 6 i--; 7 System.out.println( 阅读全文
posted @ 2017-12-01 20:19 黑土白云 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 1. 1 public class SyncDubbo1 { 2 public synchronized void method1(){ 3 System.out.println("method1..."); 4 method2(); 5 } 6 public synchronized void m 阅读全文
posted @ 2017-12-01 20:11 黑土白云 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1. 1 public class DirtyRead { 2 private String username = "ck"; 3 private String password = "123"; 4 5 public synchronized void setValue(String userna 阅读全文
posted @ 2017-12-01 20:09 黑土白云 阅读(183) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2017-12-01 19:53 黑土白云 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 1. 1 public class MultiThread { 2 private static int num = 0; 3 4 public static synchronized void printNum(String tag){ 5 if("a".equals(tag)){ 6 Syste 阅读全文
posted @ 2017-12-01 19:50 黑土白云 阅读(147) 评论(0) 推荐(1) 编辑
摘要: 1. 1 public class MyThread extends Thread{ 2 private int count = 5; 3 4 @Override 5 public synchronized void run() { 6 count--; 7 System.out.println(T 阅读全文
posted @ 2017-12-01 19:45 黑土白云 阅读(164) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2017-11-15 22:42 黑土白云 阅读(2) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 40 下一页