摘要:
多线程访问资源时,如果没有做处理,很容易出现资源错乱,必须通过锁机制实现资源共享例如:View Code 1packagemultithread;2importjava.util.HashMap;3importjava.util.Map;4importjava.util.concurrent.ConcurrentHashMap;5importjava.util.concurrent.ExecutorService;6importjava.util.concurrent.Executors;7publicclassNoLockDemo{8publicstaticvoidmain(String[] 阅读全文
摘要:
Java多线程1、创建多线程,通过继承Thread类或者实现Runnable接口View Code 1packagemultithread;2publicclassMultiThread{3publicstaticvoidmain(String[]args){4inti=5;5for(intj=0;j<i;j++){6newThread(newRunabledImp()).start();7}8System.out.println("**********************");9for(intj=0;j<i;j++){10newRunabledImp(). 阅读全文