每次在非最终类字段上同步时都会显示警告.这是代码:
public class X
{
private Object o;
public void setO(Object o)
{
this.o = o;
}
public void x()
{
synchronized (o) // synchronization on a non-final field
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我用以下方式改变了编码
public class X
{
private final Object o;
public X()
{
o = new Object();
}
public void x()
{
synchronized (o)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定上面的代码是在非final类字段上同步的正确方法.如何同步非最终字段?
在写入XML文件时,我收到了一个非常奇怪的IOException:
System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
at System.Xml.XmlDocument.Save(String filename)
Run Code Online (Sandbox Code Playgroud)
当我调用XmlDocument的Save(字符串)函数时发生错误.
发生了什么事吗?