当前位置: 首页 > news >正文

自己做电影网站wap网站 什么意思

自己做电影网站,wap网站 什么意思,中企动力做的网站后台怎么登录,网站流量统计文章目录 1、如何实现多线程交替打印字母和数字#xff0c;打印效果#xff1a;A1B2C3D4...AutomicBlockingQueueReentrantLockLockSupportSynchronizedWaitNotifyTransferQueueWay 2、实现多个线程顺序打印abc3、实现阻塞队列 1、如何实现多线程交替打印字母和数字#xff… 文章目录 1、如何实现多线程交替打印字母和数字打印效果A1B2C3D4...AutomicBlockingQueueReentrantLockLockSupportSynchronizedWaitNotifyTransferQueueWay 2、实现多个线程顺序打印abc3、实现阻塞队列 1、如何实现多线程交替打印字母和数字打印效果A1B2C3D4… Automic public class AutomicWay {volatile static char num1 A;volatile static int num2 1;static AtomicInteger atomicInteger new AtomicInteger(1);public static void main(String[] args) {new Thread(() - {for (int i 0; i 26; i) {while (atomicInteger.get() ! 1) {}System.out.print(num1);atomicInteger.set(2);}}).start();new Thread(() - {for (int i 0; i 26; i) {while (atomicInteger.get() ! 2) {}System.out.print(num2);atomicInteger.set(1);}}).start();} }BlockingQueue public class BlockingQueueWay {volatile static char num1 A;volatile static int num2 1;public static void main(String[] args) {BlockingQueue queue1 new ArrayBlockingQueue(1);BlockingQueue queue2 new ArrayBlockingQueue(1);new Thread(() - {try {for (int i 0; i 26; i) {System.out.print(num1);queue2.put(到你);queue1.take();}} catch (InterruptedException e) {e.printStackTrace();}}).start();new Thread(() - {try {for (int i 0; i 26; i) {queue2.take();System.out.print(num2);queue1.put(到你);}} catch (InterruptedException e) {e.printStackTrace();}}).start();} }ReentrantLock public class ConditionWay {volatile static char num1 A;volatile static int num2 1;public static void main(String[] args) {ReentrantLock lock new ReentrantLock();Condition conditionA lock.newCondition();Condition conditionB lock.newCondition();new Thread(() - {try {lock.lock();for (int i 0; i 26; i) {System.out.print(num1);conditionB.signal();conditionA.await();}conditionB.signal();} catch (InterruptedException e) {e.printStackTrace();} finally {lock.unlock();}}).start();new Thread(() - {try {lock.lock();for (int i 0; i 26; i) {System.out.print(num2);conditionA.signal();conditionB.await();}conditionA.signal();} catch (InterruptedException e) {e.printStackTrace();} finally {lock.unlock();}}).start();} }LockSupport public class LockSupportWay {static Thread t1,t2 null;volatile static char num1 A;volatile static int num2 1;public static void main(String[] args) {t1 new Thread(()-{for (int i 0; i 26; i) {System.out.print(num1);LockSupport.unpark(t2);LockSupport.park(t1);}});t2 new Thread(()-{for (int i 0; i 26; i) {LockSupport.park(t2);System.out.print(num2);LockSupport.unpark(t1);}});t1.start();t2.start();} }SynchronizedWaitNotify public class SyncWaitNotifyWay {volatile static char num1 A;volatile static int num2 1;public static volatile boolean flag false;public static void main(String[] args) {Object o new Object();new Thread(()-{synchronized (o){flag true;for (int i 0; i 26; i) {System.out.print(num1);try {o.notify();o.wait();} catch (InterruptedException e) {e.printStackTrace();}}o.notify();}}).start();new Thread(()-{synchronized (o){// 只是为了保证执行A的先跑// while (!flag){// try {// o.wait();// } catch (InterruptedException e) {// e.printStackTrace();// }// }for (int i 0; i 26; i) {System.out.print(num2);try {o.notify();o.wait();} catch (InterruptedException e) {e.printStackTrace();}}o.notify();}}).start();} }TransferQueueWay public class TransferQueueWay {volatile static char num1 A;volatile static int num2 1;public static void main(String[] args) {TransferQueue transferQueue new LinkedTransferQueue();new Thread(() - {try {for (int i 0; i 26; i) {System.out.print(transferQueue.take());transferQueue.transfer(num2);}} catch (InterruptedException e) {e.printStackTrace();}}).start();new Thread(() - {try {for (int i 0; i 26; i) {transferQueue.transfer(num1);System.out.print(transferQueue.take());}} catch (InterruptedException e) {e.printStackTrace();}}).start();}}2、实现多个线程顺序打印abc 核心代码 public class PrintABC {ReentrantLock lock new ReentrantLock();Condition conditionA lock.newCondition();Condition conditionB lock.newCondition();Condition conditionC lock.newCondition();private int count;public PrintABC(int count) {this.count count;}volatile int value 0;public void printABC() {new Thread(new ThreadA()).start();new Thread(new ThreadB()).start();new Thread(new ThreadC()).start();}class ThreadA implements Runnable {Overridepublic void run() {lock.lock();try {for (int i 0; i count; i) {while (value % 3 ! 0) {conditionA.await();}System.out.print(A);conditionB.signal();value;}} catch (InterruptedException e) {e.printStackTrace();}}}class ThreadB implements Runnable {Overridepublic void run() {lock.lock();try {for (int i 0; i count; i) {while (value % 3 ! 1) {conditionB.await();}System.out.print(B);conditionC.signal();value;}} catch (InterruptedException e) {e.printStackTrace();}}}class ThreadC implements Runnable {Overridepublic void run() {lock.lock();try {for (int i 0; i count; i) {while (value % 3 ! 2) {conditionC.await();}System.out.print(C);conditionA.signal();value;}} catch (InterruptedException e) {e.printStackTrace();}}} }测试代码 public static void main(String[] args) {PrintABC printABC new PrintABC(10);printABC.printABC(); }// 输出结果ABCABCABCABCABCABCABCABCABCA3、实现阻塞队列 核心代码 public class ProviderConsumerT {private int length;private QueueT queue;private ReentrantLock lock new ReentrantLock();private Condition provideCondition lock.newCondition();private Condition consumeCondition lock.newCondition();public ProviderConsumer(int length) {this.length length;this.queue new LinkedList();}public void provide(T product) {lock.lock();try {while (queue.size() length) { // 不能换成if唤醒后可能条件已经不满足了provideCondition.await();}queue.add(product);consumeCondition.signal();} catch (InterruptedException e) {e.printStackTrace();} finally {lock.unlock();}}public T consume() {lock.lock();try {while (queue.isEmpty()) { // 不能换成if唤醒后可能条件已经不满足了consumeCondition.await();}T product queue.remove();provideCondition.signal();return product;} catch (InterruptedException e) {e.printStackTrace();} finally {lock.unlock();}return null;} }测试代码 public static void main(String[] args) {ProviderConsumerInteger providerConsumer new ProviderConsumer(5);new Thread(() - {for (int i 0; i 10; i) {providerConsumer.provide(1);}}).start();new Thread(() - {for (int i 0; i 10; i) {providerConsumer.provide(2);}}).start();new Thread(() - {for (int i 0; i 100; i) {try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println(providerConsumer.consume());}}).start(); }
http://www.w-s-a.com/news/414885/

相关文章:

  • 房产网站有哪些如何自己建一个微网站
  • 青岛市黄岛区城市建设局网站手机域名访问网站怎么进入
  • 网站模板 双语河南省建设人才信息网官网
  • 网站建设备案优化之看邹城网站开发
  • 网站方案书图书馆网站建设公司
  • 公司取名网免费版在线网站优化公司
  • dw怎么做秋季运动会网站九江集团网站建设
  • 响应式网站建设服务商wordpress 非小工具形式 微博秀
  • 网站安全检测漏洞扫描风险等级分布建设一个网站步骤
  • 摄影网站的意义开发企业小程序公司
  • 龙岩网站设计招聘信息网上免费logo设计
  • 高端定制网站开发建站教程详解网站共享备案可以申请支付接口
  • 做房产网站接不到电话企业推广宣传方式
  • 网站建设费用不用摊销下一页p30
  • 北京 工业网站建设公司国外服务器公司有哪些
  • 怎样局域网站建设盈利网站
  • 公司做网站广告语济南建网站价格消费品展
  • 建德网站网站建设规划设计书
  • 谷歌网站流量分析wordpress置顶浮标
  • 江苏新宁建设集团网站网络规划设计师2023论文
  • 合作建站协议python wordpress采集器
  • 集团网站网页模板网站建设图片大全
  • 举报非法网站要求做笔录wordpress怎么插视频
  • 网站服务器防护如何搭建网站平台
  • 设计师接私活的网站如何做网站的搜索栏
  • ps做图下载网站网站子目录设计
  • 厦门网站制作策划高中生做网站网页
  • 高端品牌网站建设在哪济南兴田德润优惠吗专业定制网站开发公司
  • 怎么做网站卖东西汽车网站排行榜前十名
  • 网站关键字没有排名只有单页面的网站怎么做seo