哪位大侠能看下这段java代码哪犯病了

[复制链接]
查看11 | 回复1 | 2011-4-23 07:17:28 | 显示全部楼层 |阅读模式
package peas.crazy;

public class Demo
{

public static void main(String[] args)
{
A a = new A();
new Thread(a).start();
new Thread(a).start();
A.q= \"hh\";
new Thread(a).start();
new Thread(a).start();
}

}

class A extends Thread implements Runnable
{
static String q = \"\";
private static int tickets = 100;
public void run(){
if (\"hh\".equals(this.q))
{
boolean b = true;
while(b)
{

xixi();
}
}
else {
while(true)
{
synchronized(this)
{

if (tickets0)

{

try {sleep(100);} catch (InterruptedException e){e.printStackTrace();}

System.out.println(\"正在售票第\"

tickets-- Thread.currentThread().getName());

}
}
}
}
}
public void xixi()
{
synchronized(this)
{
if (tickets0) {
try {sleep(100);} catch (InterruptedException e) {
e.printStackTrace();}

System.out.println(\"方法售票\"

tickets-- Thread.currentThread().getName());



}
}
}
}
他一直输出的是方法买票??为什么啊 ,起码应该执行两下子正在买票把?
回复

使用道具 举报

千问 | 2011-4-23 07:17:28 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">if (\"hh\".equals(this.q))//如果我没看错,你的q这句话总是true 的。。肯定是运行的啊
{
boolean b = true;
while(b)
{

xixi();
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行