`

解决:The declared package..does not match the expected package..

 
阅读更多

解决方案1(推荐): 
只需要在project build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了。 
解决方案2: 
Windows -> Preferences -> Java -> Compiler -> Errors/Warnings -> 
Deprecated and trstricted API -> Forbidden reference (access rules): -> change to warning 

解决:
volatile在java里的作用和用法
Volatile修饰的成员变量在每次被线程访问时,都强迫从共享内存中重读该成员变量的值。而且,当成员变量发生变化时,强迫线程将变化值回写到共享内存。这样在任何时刻,两个不同的线程总是看到某个成员变量的同一个值。

Java语言规范中指出:为了获得最佳速度,允许线程保存共享成员变量的私有拷贝,而且只当线程进入或者离开同步代码块时才与共享成员变量的原始值对比。

这样当多个线程同时与某个对象交互时,就必须要注意到要让线程及时的得到共享成员变量的变化。

而volatile关键字就是提示VM:对于这个成员变量不能保存它的私有拷贝,而应直接与共享成员变量交互。

使用建议:在两个或者更多的线程访问的成员变量上使用volatile。当要访问的变量已在synchronized代码块中,或者为常量时,不必使用。

由于使用volatile屏蔽掉了VM中必要的代码优化,所以在效率上比较低,因此一定在必要时才使用此关键字。 


就跟C中的一样 禁止编译器进行优化~~~~
分享到:
评论

相关推荐

    spring boot shiro demo项目

    用springboot shiro 做的一个小demo ,方便快速入门shiro 会比security容易上手很多;

    The.Go.Programming.Language.0134190440.epub

    The book does not assume prior knowledge of Go nor experience with any specific language, so you’ll find it accessible whether you’re most comfortable with JavaScript, Ruby, Python, Java, or C++. ...

    TCLAP-1.1.0_ubuntu9_0_4

    I have fixed this bug below: ------------------------------------------ # In file included from ../include/tclap/...# ../include/tclap/MultiArg.h:103: error: ‘EOF’ was not declared in this scope

    ORB_SLAM2.tar.gz

    Linux系统,需要安装如下依赖库: #####Library ... In the manifest.xml the only declared package dependencies are roscpp, tf, sensor_msgs, image_transport, cv_bridge, which are all BSD licensed.

    a project model for the FreeBSD Project.7z

    The vision is “To produce the best UNIX-like operating system package possible, with due respect to the original software tools ideology as well as usability, performance and stability.” The ...

    DevExpress VCL_15.2.2_FS(一共2个压缩分卷,这是第2个)

    If you are building your project with runtime packages, remove the cxBarEditItemRS~ packages from the project's runtime package lists. ExpressLibrary # BC3316: The cxRectOffsetF global function ...

    thymeleaf-extras-eclipse-plugin-2.1-master.zip

    the directory it goes in must be a valid Java package name These are just short-comings of the current dialect scanning method, which itself is built upon Eclipse's own lookup mechanisms.

    DevExpress VCL_15.2.2_FS(一共2个压缩分卷,这是第1个)

    If you are building your project with runtime packages, remove the cxBarEditItemRS~ packages from the project's runtime package lists. ExpressLibrary # BC3316: The cxRectOffsetF global function ...

    ConsoleApplication1.cpp

    windows c++ vs 录音程序 cout << " 1. 开始录音" ; cout << " 2. 停止录音" ; cout << " 3. 保存录音" ; cout << " 0. 退出" ; 保存为wav格式

    Anyview4.0

    Anyview4.0史上最强大的手机电子书阅读软件,

    EHLib 6.3.171〖D7~XE5〗

    - Does not allow to leave the current record of DataSet with keyboard keys. - When the current cell in the grid is on the last line, the Tab key on the grid translates the input focus to the next ...

    codeblocks中报错:'to_string' was not declared in this scope解决方案

    codeblocks中报错:'to_string' was not declared in this scope解决方案

    Senfore_DragDrop_v4.1

    * The Shell Extension components does not support C++ Builder 4. For some strange reason the components causes a link error. * There appear to be sporadic problems compiling with C++ Builder 5. ...

    OpenGL库(多版本打包在一起)

    Header Declared: #include<gl.h> #include<glu.h> Import Library: opengl.lib glu.lib Import DLL: opengl.dll glu.dll ======== GLUT Library ======== Header Declared: #include<gl\glut.h> Import...

    acpi控制笔记本风扇转速

    _HID does not match the predefined PCI Root Bridge IDs, the _CID list (if present) is now obtained and also checked for an ID match. Implemented additional support for the PCI _ADR execution: up...

    keil常见错误.pdf

    keil常见错误 main.c(35): warning: #128-D: loop is not reachable from preceding code main.c(54): warning: #1-D: last line of file ...main.c(31): warning: #223-D: function "initNvic" declared implicitly

    ORACLE DBMS STATS ERROR

    DBMS STATS Package Fails with Error 'ORA-04063: package body "SYS.DBMS_REGISTRY_SYS" has errors'

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    handling capabilities, and the use of assertions to validate the expected behavior of code. <br>Chapter 13Strings and Regular Expressionsdescribes the built-in language and runtime support for ...

    aria2-1.34.0.tar.7z解决了github下载的原版文件在linux中make报错问题一共解决了两个问题

    --------bignum.h:34:25: error: ‘make_unique’ was not declared in this scope inline ulong() : buf_(make_unique[]>(dim)) {} --------------这个问题 以及一个是是关于 /* libc already has support */ ...

    JSP Simple Examples

    Suppose if we have declared an array of type int then the array will take only the int values and not any other data types. We can find find out the length of the variable by using the variable ...

Global site tag (gtag.js) - Google Analytics