zoukankan      html  css  js  c++  java
  • Java Concurrency (1)

    Memory that can be shared betweenthreads is called shared memory or heap memory. The term variable as used inthis technical report refers to both fields and array elements. Variables thatare shared between threads are referred to as shared variables. All instance fields,static fields, and array elements are shared variables allocated in heapmemory. Local variables, formal method parameters, and exception-handlerparameters are never shared between threads and are not affected by the memorymodel.

    The visibility of writes toshared variables can be problematic because the value of a shared variable maybe cached and not written to main memory immediately. Consequently, anotherthread may read a stale value of the variable.

    A further concern is thatconcurrent executions of code are typically interleaved, and statements may bereordered b the compiler or runtime system to optimize performance. Thisresults in execution orders that are not immediately obvious when the sourcecode is examined. Failure to account for possible reordering is a common sourceof data races.

    Volatile accesses do notguarantee the atomicity of composite operations such incrementing a variable.Consequently, volatile is not applicable in cases where the atomicity ofcomposite operations must be guaranteed.

    A correctly synchronized programis one whose sequentially consistent executions do not have any data races.

    Correct visibility guaranteesthat multiple threads accessing shared data can view each others’ results, butdoes not establish the order of when each thread reads or writes the data.Correct synchronization guarantees that threads access data in a proper order.

  • 相关阅读:
    第一个springMVC项目
    spring声明式事务
    spring整合mybatis
    spring中的Aop
    java代理模式(23种设计模式之一)
    java注解与反射
    spring之自动装配bean
    zookeeper端口修改后无法启动客户端
    vue的学习-简单指令(一)
    springsecurity 安全管理
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3187000.html
Copyright © 2011-2022 走看看