关于在Integer上进行同步时,为什么notifyAll和引发IllegalMonitorStateException?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.IllegalS
关于在Integer上进行同步时,为什么notifyAll和引发IllegalMonitorStateException?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于.IllegalStateException: User did not initialize spark context! 咋整、android – 如何在Cursor上处理代码IllegalStateException?、Android:java.lang.IllegalMonitorStateException:对象在wait()之前没有被线程锁定、com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions ...等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- 在Integer上进行同步时,为什么notifyAll()引发IllegalMonitorStateException?
- .IllegalStateException: User did not initialize spark context! 咋整
- android – 如何在Cursor上处理代码IllegalStateException?
- Android:java.lang.IllegalMonitorStateException:对象在wait()之前没有被线程锁定
- com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions ...
在Integer上进行同步时,为什么notifyAll()引发IllegalMonitorStateException?
为什么此测试程序会导致java.lang.IllegalMonitorStateException
?
public class test { static Integer foo = new Integer(1); public static void main(String[] args) { synchronized(foo) { foo++; foo.notifyAll(); } System.err.println("Success"); }}
结果:
Exception in thread "main" java.lang.IllegalMonitorStateException at java.lang.Object.notifyAll(Native Method) at test.main(test.java:6)
答案1
小编典典您已经正确地指出了notifyAll
必须从同步块中调用。
但是,在您的情况下,由于自动装箱,您在其上同步的对象与您在其上调用的实例不同notifyAll
。实际上,新的,递增的foo
实例仍然被限制在堆栈中,并且其他线程可能不会在wait
调用中被阻塞。
您可以实现自己的可变计数器来执行同步。根据您的应用程序,您可能还会发现AtomicInteger满足您的需求。
.IllegalStateException: User did not initialize spark context! 咋整
3 INFO storage.BlockManagerMaster: BlockManagerMaster stopped
20/04/03 17:16:23 INFO scheduler.OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
20/04/03 17:16:23 INFO spark.SparkContext: Successfully stopped SparkContext
20/04/03 17:16:23 INFO yarn.ApplicationMaster: Final app status: FAILED, exitCode: 13
20/04/03 17:16:23 ERROR yarn.ApplicationMaster: Uncaught exception:
java.lang.IllegalStateException: User did not initialize spark context!
at org.apache.spark.deploy.yarn.ApplicationMaster.runDriver(ApplicationMaster.scala:464)
at org.apache.spark.deploy.yarn.ApplicationMaster.run(ApplicationMaster.scala:275)
at org.apache.spark.deploy.yarn.ApplicationMaster
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1875)
at org.apache.spark.deploy.yarn.ApplicationMaster$.main(ApplicationMaster.scala:804)
at org.apache.spark.deploy.yarn.ApplicationMaster.main(ApplicationMaster.scala)
20/04/03 17:16:23 INFO yarn.ApplicationMaster: Deleting staging directory hdfs://rongan/user/hbase/.sparkStaging/application_1585536197032_1593
20/04/03 17:16:23 INFO util.ShutdownHookManager: Shutdown hook called
20/04/03 17:16:23 INFO util.ShutdownHookManager: Deleting directory /data/yarn/nm/usercache/hbase/appcache/application_1585536197032_1593/spark-572f18e5-c65d-4c45-a3b7-22d66bff7201
android – 如何在Cursor上处理代码IllegalStateException?
当我调试我的应用程序突然出现此错误时.
我该如何处理这种错误?
我不知道在哪里以及如何造成.
Daemon System Thread [<5> HeapWorker] (Suspended (exception IllegalStateException))
sqliteCursor.finalize() line: 603
NativeStart.run() line: not available [native method]
解决方法:
使用managedQuery()函数查询数据.如果使用managedQuery()而不是query(),则Activity将保留Cursor的引用,并在不使用时自动关闭它.
Android:java.lang.IllegalMonitorStateException:对象在wait()之前没有被线程锁定
我有此代码为Android停留在同步语句.即使我删除了process1.wait(),我也捕捉到异常.对您有帮助吗?
private class LongOperation extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... params)
{
try
{
Process process1 = new ProcessBuilder("sh", "/data/local/bin/tcpdump.sh").start();
synchronized(process1){
process1.wait();
}
}
catch (Exception e)
{
Log.e("Tcpdump function error", "Unable to capture the packets into the buffer");
}
return null;
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result)
{
try
{
StringBuffer output = new StringBuffer();
File file = new File("/data/local/bin/dump.txt");
BufferedReader br = new BufferedReader(new FileReader(file), 8 * 1024);
String line;
while ((line = br.readLine()) != null)
{
output.append(line + "\n");
}
tv.setText(output);
setContentView(tv);
}
catch (Exception e)
{
e.printstacktrace();
}
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onProgressUpdate(Progress[])
*/
@Override
protected void onProgressUpdate(Void... values)
{
}
}
tcpdump.sh有这一行
tcpdump -c 10> /data/local/bin/dump.txt
解决方法:
您确定要调用Process.waitFor()吗?不是wait()?
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions ...
学习 CXF 的 JAXB 时遇到的小问题
利用 JAXB 把 java 对象 转换为 xml
package com.example.test;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name="student")
@XmlType(name = "student", propOrder = { "name","ClassName" })
public class Student {
private String name;
private String ClassName;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClassName() {
return ClassName;
}
public void setClassName(String className) {
className = className;
}
}
工具类
package com.example.test;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class JAXBUtil {
public static String toXml(Object o){
StringWriter writer = new StringWriter();
try {
Class obj = o.getClass();
JAXBContext jaxbContext = JAXBContext.newInstance(obj);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(o, writer);
} catch (JAXBException e) {
e.printStackTrace();
}
return writer.toString();
}
}
测试类
package com.example.test;
public class JaxbHelperTest {
public static void main(String[] args) {
Student stu = new Student();
stu.setName ("小明");
stu.setClassName ("三一班");
System.out.println(JAXBUtil.toXml(stu));
}
}
运行后报错 实在是大意了,最后把实体类的 属性 ClassName 改为 className 问题解决,应该是实体类的属性第一个字母不能大写。
package com.example.test;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name="student")
@XmlType(name = "student", propOrder = { "name","className" })
public class Student {
private String name;
private String className;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
className = className;
}
}
关于在Integer上进行同步时,为什么notifyAll和引发IllegalMonitorStateException?的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于.IllegalStateException: User did not initialize spark context! 咋整、android – 如何在Cursor上处理代码IllegalStateException?、Android:java.lang.IllegalMonitorStateException:对象在wait()之前没有被线程锁定、com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions ...等相关内容,可以在本站寻找。
本文标签: