`

解决: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项目

    Spring Boot Shiro Demo项目是一个基于Spring Boot框架与Apache Shiro实现的权限管理示例,旨在帮助开发者快速理解和应用Shiro进行权限控制。相比Spring Security,Shiro通常被认为更易于理解和使用,更适合小型到...

    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.

    最常见的VC++编译错误信息_fatal_error

    11. Error C2509:'OnTimer' : member function not declared in 'CHelloView' 这是一个常见的编译错误,原因是成员函数“OnTimer”没有在“CHelloView”中声明。解决方法是检查成员函数的声明是否正确。 12. ...

    ORACLE DBMS STATS ERROR

    - `PLS-00302: component 'IS_STATS_FROM_UPGRADE' must be declared` - `ORA-04063: package body "SYS.DBMS_REGISTRY_SYS" has errors` - `ORA-04063: package body "SYS.DBMS_STATS" has errors` 这些错误表明`...

    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 ...

    解决Android Studio 3.0 butterknife:7.0.1配置的问题

    网上教程7.0大多数配置是这样compile ‘com.jakewharton:butterknife:7.0.1′ ,不知道他们用的Android Studio是多少版本,我用... The following dependencies on the compile classpath are found to contain annota

    如何使用eclipse打开已有工程.docx

    The declared package does not match the expected package appendixaStringer.java Thinking in Java/appendixaline 12022 年 11 月 11 日 14:11:20 3870 可以添加 package appendixa 命令来解决。 在运行程序时...

    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.

    C 语言常见错误 .txt

    #### 十一、`error C2509: 'OnTimer': member function not declared in 'CHelloView'` **错误说明:** 成员函数`OnTimer`没有在类`CHelloView`中声明。 **解决方案:** 1. **添加函数声明**:在类`CHelloView`的...

    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 ...

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

    在Code::Blocks中遇到“'to_string' was not declared in this scope”的错误,通常是由于编译器版本过低或者没有包含正确的头文件所导致的。`std::to_string`是C++11标准引入的一个函数,用于将数字转换为字符串。...

    20种VC++编译错误信息

    Note: C++ does not support default-int - **描述**:未指定类型,默认假定为int。 - **原因**: - 变量声明时未指定类型。 - **解决方法**: - 明确指定类型。 ### 16. 错误 C4503: decorated name length ...

    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 ...

    CentOS7升级GCC版本到gcc 8.3.0,解决GLIBCXX-3.4.21 not found 问题

    解决/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 问题 步骤如下: 解压文件: $ unzip gcc-8.3.0.zip 解压完成,进入文件目录: $ cd gcc-8.3.0 利用源码包里自带的工具下载所需要的依赖项: $ ./...

    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...

Global site tag (gtag.js) - Google Analytics