- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到此错误:
"non-static method isAlive() cannot be referenced from a static context"
这段代码有什么问题..请。
我想检测线程是否还活着...代码方面的任何帮助将不胜感激..谢谢最大
class RecThread extends Thread {
public void run() {
recFile = new File("recorded_track.wav");
// Output file type
AudioFileFormat.Type fileType = null;
fileType = AudioFileFormat.Type.WAVE;
// if rcOn =1 thread is alive
int rcOn;
try {
// starts recording
targetDataLine.open(audioFormat);
targetDataLine.start();
AudioSystem.write(new AudioInputStream(targetDataLine),
fileType, recFile);
if (RecThread.isAlive() == true) {
rcOn =1;
}
else {
rcOn =0;
}
} catch (Exception e) {
showException(e);
}
// update actions
recAction.setEnabled(true);
stopRecAction.setEnabled(false);
}
}
最佳答案
if (RecThread.isAlive() == true) {
这条线有问题。 isAlive() 不是静态方法,这意味着它只能作用于 Thread 的实例。您可以通过使用类型 (RecThread) 而不是对象来调用它,从而在静态上下文中使用它。
关于java - isAlive 问题..帮助理解它是如何工作的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666968/
我有一个 MyTunnel 类,它扩展了 Thread 类: public class MyTunnel extends Thread { protected Object obj;
我收到此错误: "non-static method isAlive() cannot be referenced from a static context" 这段代码有什么问题..请。 我想检测线
我需要一些有关 isAlive() 和 join() 函数的帮助。我了解如何以以下形式实现 isAlive() 和 join(): public class mthread implements Ru
我是多线程新手;这是启动线程的正确方法吗? if(!sesThread.isAlive()) { try { sesThread.start(); }catch(Ill
我正在尝试使用 isALive 和 join 方法,但它抛出一个错误,如找不到符号....请告诉我这个程序中的错误到底在哪里。join 方法的用途是什么。我知道这是等待线程完成,但我想要详细信息。 c
我正在寻找一种方法来在对象引用被垃圾回收时偷偷调用回调函数。 我知道我可以将对象包装在一个弱引用中,但我仍然需要轮询一组引用以了解状态更改。 我宁愿不进行轮询,因为当什么都没有发生时,这似乎是在浪费
在 Web Controller 中,我有一个接收请求的父线程。有些请求需要很长时间才能处理。为了防止客户端超时,我将父线程设置为每 2 秒发回一个字节,而子线程正在执行操作的耗时部分。 我想确保我考
这个问题已经有答案了: Thread.isAlive() vs Thread.join() (3 个回答) 已关闭 9 年前。 有两种方法可以确定线程是否已完成。首先,您可以调用isAlive()在线
当我调用 isAlive() 时,我看到的代码形式如下:m.thrd.isAlive()。 m 实现可运行接口(interface)。 thrd 是 Thread 的对象。 我理解isAlive()是
作为 this question 的后续行动,我有以下代码: using System; using System.Runtime.InteropServices; namespace Console
如解释here ,如果 WeakReference 的 IsAlive 返回 true,则它不可信任。现在,我正在尝试了解 correct way使用这个: 不正确: WeakReference do
这个问题在这里已经有了答案: How can I wait for a thread to finish with .NET? (11 个答案) 关闭 3 年前。 我在标签点击事件中启动了一个线程。
我正在写一个函数 IsAlive采取IObservable , 和时间跨度,并返回 IObservable规范用例是检测流服务器是否仍在发送数据。 我为此提出了以下解决方案,但觉得它的工作原理并不是最
我开始知道下面的代码输出为 false ,但是当我们看到这个 Thread 实例时,我们创建的 thread 被设置为守护进程并且仍在运行,那么为什么方法调用 thread.isAlive() 会返回
有一个名为r1的可运行方法 Runnable r1=new Runnable(){ @Override public void run(){ //some code here
我有一些java脚本来检查小程序是否在加载页面的其余部分之前完成加载。它已经工作了很多年,现在似乎在 Firefox 16 和 IE 7 中失败。它在 IE 8 中工作 关于它为何损坏以及如何修复它有
如果我遍历 Weakreference 列表,在通过 _ref.IsAlive 验证后,我如何确定该引用仍然存在? 例如我有这段代码,其中 scopeReferences 是 Weakreferenc
这个问题已经有答案了: Why does an IllegalThreadStateException occur when Thread.start is called again (7 个回答)
我有两个按钮,当用户单击第一个按钮时,它将启动一个线程来更新 UI,当用户单击第二个按钮时,应用程序将为第一个线程设置一个 boolean 变量以不允许它更新线程,然后它将启动第二个线程。这是我的 R
为什么 isAlive() 方法在 Thread.java 中被声明为 native?哪个类实现了这个?我知道 native 方法是在 Java 之外实现的。实现它的类是通过加载相应的库来加载的。但是
我是一名优秀的程序员,十分优秀!