- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
public class Qn {
static class Friend {
private final String name;
public Friend(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
// recipient - the person who greets
public synchronized void sayHi(Friend recipient) {
System.out.format("%s" + " said hi to %s %n",
this.name, recipient.getName());
}
}
public static void main(String[] args) {
final Friend john = new Friend("John");
final Friend peter = new Friend("Peter");
new Thread(new Runnable() {
public void run() {
john.sayHi(peter);
}
}, "thread1").start();
}
}
问题:
如果理解正确,请澄清以下内容
当调用john.sayHi()
时,线程thread1
已获取内在锁定 john
对象,以便访问 john
对象的 sayHi()
方法。
线程thread1
在JVM中独立运行。
我在网上看到这些说法,不知道他们的意思! 【线程怎么可以运行在对象上!!!事实上线程执行代码,对吗?]
线程 thread1
未在 JVM 内的任何其他对象上运行。
线程永远不会在任何对象上运行。线程永远不会由对象执行。一个线程永远不会在任何其他线程上运行。线程总是直接在 JVM 中运行。
最佳答案
When invoking
john.sayHi()
, the Threadthread1
has acquired intrinsic lock ofjohn
object in-order to access thesayHi()
method of john object.
更准确地说:
当调用john.sayHi()
时,线程thread1
将等待,直到它可以获取john
上的锁,然后再执行说嗨
。一旦获得锁,它将执行sayHi。当方法退出时,它将释放锁。
The Thread
thread1
is running independently in JVM.
独立于什么?其他线程?是的,直到它尝试获取锁。此时,它可能会受到其他线程的阻碍。当它有锁时,它可以阻止其他线程。
The thread
thread1
is not running on any other object inside the JVM.
线程在 CPU 上运行,而不是在对象上运行。
你是问一个线程是否可以并行执行多个方法?如果是这样,答案是否定的。
A thread never runs on any object.
线程在 CPU 上运行,而不是在对象上运行。
A thread is never executed by an object.
线程不由任何东西执行。线程执行代码。
A thread never runs on any other thread.
线程在CPU上运行,而不是线程。
A thread always run directly in JVM.
JVM 有一个虚拟 CPU,线程在该虚拟 CPU 上运行。
关于Java线程: Please clarify this understanding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23414744/
我的应用程序中有一些漫长的过程,因此我创建了一个WAIT PLEASE表单,然后在另一个线程上调用,如下所示: public void ShowWait() { continu
public class Qn { static class Friend { private final String name; public Friend
我正在尝试在 Excel VBA 中创建请稍候消息。这是为了提醒处理 SQL 查询的用户该过程仍在进行中。我希望将此消息显示在用户表单中。 当前,用户连接到 SQL DB,选择数据库和一些其他选项,按
我正在尝试整理来自不同媒体的报道相同故事的新闻文章,我正在使用 news-please python 库。以下代码使用给定的 URL 为我提供新闻,但我想获取多篇新闻文章(基于特定日期或日期范围)。有
我有一个严重的问题:我已经下载了最新版本的 NLTK我得到了一个奇怪的 POS 输出: import nltk import re sample_text="start please with me"
提交此 JSP 时,应要求用户选择除“请选择”之外的其他内容。如果用户选择“请选择”并提交表单,它应该通过弹出窗口提醒用户应该更改该字段。 Please Select
我有一个包含 HTML 表单的页面,一旦用户单击返回的搜索结果列表中的链接,该表单就会提交回自身。一旦他们点击链接,页面就会获取提交的变量,在各种外部 API 上运行一堆搜索,解析一堆数据,并将一堆东
我有一个很长的任务,并且在执行过程中显示“请等待”消息。我使用 SwingWorker 来实现。但有时长任务并不长,所以我想延迟 1 秒显示消息,但我不知道该怎么做。 SwingWorker mySw
我有一个通过 .net Web 服务检查用户名可用性的 Activity ,我需要在调用期间显示“请稍候”消息,因为它可能需要一两秒钟 - 我已经尝试过 AsyncTask 和 Threading,但
我有以下 3 个表: storage ( id, client, cost, -- which have no values col_1, -- which have no values col_2,
我想添加“请选择...”作为组合框中的第一个选项。请参阅下面的代码 - 有什么建议吗? 问候,彼得 "; $sql[0] = 'Please select...'; while ($row = mys
我的表单将运行一些可能需要一段时间才能执行的代码。我想在后台运行操作时显示“请稍候”消息。 我想将该消息保存在一种形式中,我可以从其他形式控制它的可见性以及它的文本。 我还希望将其设置为在 Progr
我想模拟friendlyARM的板子,Mini2440或者mini6410,这样我就可以练习嵌入式编程,QT编程等等,由于一些经济困难和奇怪的进口政策,我的国家。 无论如何,问题是我似乎无法理解进行仿
我有以下 jQuery 函数,它会在用户水平滚动超过 500 像素时触发 aTestEvent(): jQuery(document).scroll(function(){ if(jQuery
我有应用服务器,我使用 Chef + 一些临时 bash 脚本一起引导它们。问题是,当我想在这些应用程序服务器之一上运行更新时,我得到: 19:00:28: *** Please tell me wh
我有这个bootstrap-table数据表,加载完所有数据后,消息继续显示。任何人都知道为什么会这样?提前谢谢你。 Id
我需要在应用程序启动,动画启动以及应用程序更改可见性的生命周期中创建一个“请稍候”窗口。我不想创建明确的新线程(可能是ThreadPool或BackgroundWorker)。 有任何想法吗? 最佳答
我正在使用3rd party库,该库的某些功能需要很长时间才能执行,因此我想在功能繁忙时显示“请稍候”对话框。 通常我会做这样的事情: Thread longTask = new Thread (ne
我想让我的选择器在启动时显示“默认选项”。这意味着:类似“请选择一个选项”。 我尝试使用此短语手动添加选项,但是,这样在选择其他选项后可以重新选择“默认选项”,就像它是真正的选项之一一样。有什么办法可
我一直在努力制作一个模态表单来通知用户等待作业结束。这是我正在尝试做的一个简单示例: unit Unit1; interface uses Winapi.Windows, Winapi.Messa
我是一名优秀的程序员,十分优秀!