Channels and Concurrency Considerations (Thread Safety)

翻译 2018年04月15日 15:19:58

As a rule of thumb, sharing Channel instances between threads is something to be avoided. Applications should prefer using Channel per thread instead of sharing the same Channel across multiple threads.

While some operations on channels are safe to invoke concurrently, some are not and will result in incorrect frame interleaving on the wire, double acknowledgements and so on.

Concurrent publishing on a shared channel can result in incorrect frame interleaving on the wire, triggering a connection-level protocol exception and immediate connection closure by the broker. It therefore requires explicit synchronization in application code (Channel#basicPublish must be invoked in a critical section). Sharing channels between threads will also interfere with Publisher Confirms. Concurrent publishing on a shared channel is best avoided entirely, e.g. by using a channel per thread.

It is possible to use channel pooling to avoid concurrent publishing on a shared channel: once a thread is done working with a channel, it returns it to the pool, making the channel available for another thread. Channel pooling can be thought of as a specific synchronization solution. It is recommended that an existing pooling library is used instead of a homegrown solution. For example, Spring AMQP which comes with a ready-to-use channel pooling feature.

JavaSE之多线程实战视频课程

多线程的概念 在Java中实现多线程 Thread类 Runnable接口 线程的生命周期和线程状态 后台线程 线程同步
  • 2016年10月12日 11:25

Thread Safety

thread safe
  • wwq518
  • wwq518
  • 2016-03-12 15:46:03
  • 423

XAMPP 1.7.4 Thread Safety的debug调试

部分摘自http://zhouhongquan.com/archives/2010/05/zend-debugger-and-php-5-3.html最近使用xampp 1.7.4,原来在调试的时候,...
  • jallin2001
  • jallin2001
  • 2011-07-06 16:10:45
  • 4500

JMeter Test Plan的组成部分之Thread Group

JMeter Test Plan的组成部分之Thread Group A Thread Group is the starting point of a Test Plan, and it sh...
  • doctor_who2004
  • doctor_who2004
  • 2016-03-27 17:22:31
  • 1882

线程安全总结(ThreadSafety Summary)

线程安全总结(ThreadSafety Summary) 本附录描述OS X和iOS中高级线程安全的一些关键框架。本附录中的信息可能发生变化。 Cocoa Cocoa中多线程使用指南包括以下几点: ...
  • iosswift
  • iosswift
  • 2015-03-24 20:23:22
  • 2125

如何判断PHP 是线程安全还是非线程安全的

什么是线程安全与非线程安全? 线程安全就是在多线程环境下也不会出现数据不一致,而非线程安全就有可能出现数据不一致的情况。 线程安全由于要确保数据的一致性,所以对资源的读写进行了控制,换句话说增加...
  • aoyoo111
  • aoyoo111
  • 2014-02-09 23:29:47
  • 14536

Concurrency Program(并发编程)

Introduction Different Concurrency Program Process-based event-based thread-based Posix ThreadsPThre...
  • c602273091
  • c602273091
  • 2016-12-09 15:04:46
  • 790

jmeter应用---测试元件介绍(一)

概述构成测试计划的基本组件,测试至少包含一个测试计划、一个线程组、一个或多个取样器测试计划新建测试时,默认会有一个测试计划,是指定测试的总体设置的地方。public JMeterTreeModel()...
  • yue530tomtom
  • yue530tomtom
  • 2017-10-13 18:04:49
  • 470

线程安全和不可变性(Thread Safety and Immutability)

原文链接:http://tutorials.jenkov.com/java-concurrency/thread-safety-and-immutability.html竞争条件只会在多个线程访问相同...
  • shfqbluestone
  • shfqbluestone
  • 2015-05-29 15:10:41
  • 633

Java设计模式之--享元模式(Flyweight Pattern)

享元模式(Flyweight Pattern)是一种软件设计模式。它使用共享物件,用来尽可能减少内存使用量以及分享资讯给尽可能多的相似物件;它适合用于只是因重复而导致使用无法令人接受的大量内存的大量物...
  • lqh517
  • lqh517
  • 2016-06-21 10:37:39
  • 130
收藏助手
不良信息举报
您举报文章:Channels and Concurrency Considerations (Thread Safety)
举报原因:
原因补充:

(最多只允许输入30个字)