每日一练
来源:互联网 发布:vue服务端渲染java 编辑:程序博客网 时间:2024/06/11 19:39
//多线程小程序 复习
class Ticket implements Runnable
{
Object obj=new Object();
Boolean flag=true;
private int tick=100;
public void run()
{
if (flag)
{
while (true)
{synchronized(this)
{ if (tick>0)
{
try
{
Thread.sleep(10);
}
catch (Exception e)
{
}
System.out.println(Thread.currentThread().getName()+"`````cold ``"+tick--);
}
}
}
}
else
{while(true)
show();
}
}
public synchronized void show()
{
if (tick>0)
{
try
{
Thread.sleep(10);
}
catch (Exception e)
{
}
System.out.println(Thread.currentThread().getName()+"`````show``` ``"+tick--);
}
}
}
public class TicketDemo
{public static void main(String args[])
{
Ticket t=new Ticket();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
t1.start();
try
{
Thread.sleep(10);
}
catch (Exception e)
{
}
t.flag=false;
t2.start();
//Thread t3=new Thread(t);
//Thread t4=new Thread(t);
//t3.start();
//t4.start();
}
}
- 算法每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- 每日一练
- Android优化之优化Java代码
- POJ1273:Drainage Ditches
- u-boot启动linux内核
- 不用临时变量也可以交换变量的值
- WPF、Windows Forms和Silverlight间的联系和区别
- 每日一练
- ZOJ 1094_Matrix Chain Multiplication
- svm资源
- 经典 Javascript 正则表达式
- cygwin下把window下dll文件转换成a或者so文件的方法
- asp.net地址映射——伪静态
- 基于多特征集成的图像自动标注方法研究
- UNIX 高手的 10 个习惯
- Ubuntu下Hadoop快速安装手册