天道酬勤/
2017-09-18 07:37请问在2个方法中,如果没有放入变量,为什么能用this
class Resource
{
private String name;
private int num=1;
boolean flag=false;
public synchronized void setName(String name)
{
if(flag)
{
try
{
this.wait();
}
catch (InterruptedException e)
{
}
}
this.name=name+num;
num++;
System.out.println(Thread.currentThread().getName()+"..生产.."+this.name);
flag=true;
this.notify();
}
public synchronized void getName()
{
if(!flag)
{
try
{
this.wait();
}
catch (InterruptedException e)
{
}
}
System.out.println(Thread.currentThread().getName()+"..销售.."+this.name);
flag=false;
this.notify();
}
}
在上面的代码上,getName方法里为什么能用this.name?
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 将堆栈跟踪放入字符串变量
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- 使用PHP将子页面放入变量而不是使用$ _GET [duplicate]
- get
- post
- php
- 4个回答
- 从javascript数组中获取值并将其放入php变量中
- javascript
- php
- jquery
- 2个回答
- 从foreach循环内部调用变量以放入数组内部
- json
- foreach
- arrays
- php
- 2个回答
- 将数据库中的MySQL数据放入变量中
- select
- mysql
- php
- 1个回答
换一换