thread confinement就是线程范围上安全的
1.Ad-hoc Thread Confinement,当每个对象只被一个线程用时就是Confinement的
2. Stack Confinement,在栈上Confinement。如下animals就是Confinement的,因为是局部变量。
public int loadTheArk(Collection<Animal> candidates) {
SortedSet<Animal> animals;
int numPairs = 0;
Animal candidate = null;
// animals confined to method, don't let them escape!
animals = new TreeSet<Animal>(new SpeciesGenderComparator());
animals.addAll(candidates);
for (Animal a : animals) {
if (candidate == null || !candidate.isPotentialMate(a))
candidate = a;
else {
ark.load(new AnimalPair(candidate, a));
++numPairs;
candidate = null;
}
}
return numPairs;
}
3.用ThreadLocal,(threadlocal自己可以查看源代码)
private static ThreadLocal<Connection> connectionHolder
= new ThreadLocal<Connection>() {
public Connection initialValue() {
return DriverManager.getConnection(DB_URL);
}
};
public static Connection getConnection() {
return connectionHolder.get();
}
interrupt和stop的区别:
如果该线程处在可中断状态下,(调用了xx.wait(),或者Selector.select(),Thread.sleep()等特定会发生阻塞的
api),那么该线程会立即被唤醒,同时会受到一个InterruptedException,同时,如果是阻塞在io上,对应的资源会被关闭。如果该线
程接下来不执行“Thread.interrupted()方法(不是interrupt),那么该线程处理任何io资源的时候,都会导致这些资源关闭。interrupt不会导致线程直接退出,还是会在继续执行run函数。
Stop会让线程直接退出。
分享到:
相关推荐
- 线程封闭(Thread Confinement):一种确保线程安全的策略,通常通过ThreadLocal等机制实现。 - 不可变对象(Immutable Objects):一旦创建就不能被修改的对象,天然线程安全。 学习Java并发编程,重点在于理解...
在多线程环境下,对象的可见性(Visibility)、发布(Publication)和逃逸(Escape)、线程封闭(Thread Confinement)、不可变性(Immutability)以及安全发布(Safe Publication)是实现线程安全的关键概念。...
1. 夸克禁闭(Quark Confinement):在量子色动力学(Quantum Chromodynamics, QCD)的框架下,夸克是构成强子(如质子和中子)的基本粒子。夸克禁闭是指夸克永远无法被独立分离出来,只能以组合形式(如夸克-反夸克...
Confinement is used to prohibit safety-critical objects from unintended access. Approaches for specifying and verifying confinement have been proposed in the last twenty years but their application ...
A new configuration of the confinement structure is utilized to improve optoelectronic performance, including threshold current, ac current gain, optical bandwidth, and optical output power of a ...
In this Letter, blue phosphorescence organic light-emitting diodes (PHOLEDs) employ structures for electron and/or hole confinement; 1,3,5-tris(N-phenylbenzimiazole-2-yl)benzene is used as a hole ...
纳米CdS and CdSe 发光蓝移:量子限域或量子测不准?,孙长庆,S. LI,Blue shift of semconductor nanosolids is shown arise from surface bond contraction rather than
A method for inertial confinement fusion driven by powerful long wavelength electromagnetic pulses (EMPs), such as
"cow-confinement:CERC2015解决的问题"是一个基于2015年中欧区域竞赛中的实际问题,该问题关注的是优化牛圈养的策略。在这个问题中,参赛者可能面临如何在有限的空间内有效地安排母牛的饲养,以最大化效益或满足特定...
标题“plasma_confinement”涉及的是等离子体约束技术,这是核聚变研究中的一个核心领域。等离子体是物质的第四态,由高度电离的原子组成,具有独特的电磁性质。在核聚变反应中,高温高能的等离子体需要被有效地约束...
Confinement loss in hollow-core negative curvature fiber: A multi-layered model
One reason these factors have a large impact on the performance of inertial confinement fusion implosions is the high convergence required to achieve high fusion gains. To tackle these problems, a ...
A unique approach for permeation filling of nonpermeable inertial confinement fusion target capsules with deuterium–tritium (DT) is presented. This process uses a permeable capsule coupled into the ...
In the 9th laser system of Shenguang II inertial confinement fusion (ICF) facility, tunable Fabry-Perot (F-P) filter is applied to compensate the FM-AM effect. According to the technical requirements ...
As our understanding of the environmental impact of fossil fuel based energy production increases, it is becoming clear that the world needs a new energy solution to meet the challenges of the future....
As the basic conditions for laser inertial confinement fusion (ICF) research, the targets are required to be well specified and elaborately fabricated. Because of the characteristics of the targets, ...
The Be-based materials with many particular properties lead to an important research subject. The investigation progresses in the fabrication technologies are introduced here, including main three ...
标题和描述中提到的是一项关于光子晶体光纤(Photonic Crystal Fiber, PCF)的研究,该光纤具有高度非线性和低限制损失的特性,基于四孔单元结构。下面将详细阐述这一技术的关键知识点。 首先,光子晶体光纤是一种...