- 浏览: 126950 次
- 性别:
- 来自: Singapore
文章分类
- 全部博客 (112)
- Tiger Thread (18)
- Perforce (6)
- Spring (5)
- maven (3)
- log4j (3)
- Quartz Scheduler (4)
- unix and linux (12)
- hibernate (3)
- Enum (1)
- Futures and Options (1)
- Market Making (2)
- Java Basic (11)
- Tibco EMS (3)
- F I X message (5)
- equity derivative (2)
- Sybase (3)
- XML (1)
- JUnit (2)
- J A X B 2.0 (1)
- N I O (1)
- windows batch file (1)
- Cruise Control (1)
- util Class (5)
- ant (1)
- JMS (1)
- profiling (0)
- Sql Server (6)
- GXT (2)
- eclipse (1)
- Generics (1)
- Tibco RV (3)
- Autosys (0)
- Message (1)
最新评论
-
houzhe11:
<property name="proxyTa ...
AOP usage -- BeanNameAutoProxyCreator usage
/**
* A standard implementation for Delayed interface
*
* A Delayed instance means something which has a time attribute. Generally means a thread
* will start up this time later.
*
* And obviously, Delayed instances can be compared with each other – which one sooner,
* which one is later. So, Delayed extends Comparable<Delayed>
*
* Delayed instances can be put into DelayQueue.
* DelayQueue is declared in the following way:
* DelayQueue<E extends Delayed>
*
* DelayQueue has 2 characters:
* 1) All Delayed instances are automatically sorted – the most urgent Delayed instance will
* be returned when take() method is called on the DelayQueue
* 2) Only Expired Delayed instances are visible in the DelayQueue – if no expired instance
* – take() method will block.
*
* From this point of view, DelayQueue is an advanced unbounded BlockingQueue
*
*/
class DelayedTask implements Runnable, Delayed
{
private final int delta;
private final long trigger;
public DelayedTask(int delayInMilliseconds)
{
delta = delayInMilliseconds;
trigger = System.nanoTime() + NANOSECONDS.convert(delta, MILLISECONDS);
}
//--These 2 methods are required by Delayed interface, you must implement them
//--And exactly in this way----------------------------------------------------
//--Delayed interface extends Comparable<Delayed>------------------------------
public long getDelay(TimeUnit unit)
{
return unit.convert(trigger - System.nanoTime(), NANOSECONDS);
}
public int compareTo(Delayed arg)
{
DelayedTask that = (DelayedTask) arg;
if (trigger < that.trigger) return -1;
if (trigger > that.trigger) return 1;
return 0;
}
//-----------------------------------------------------------------------------
}
Another thing to mention is TimeUnit convert.
NANOSECONDS.convert(delta, MILLISECONDS);
This line means delta is a value in MILLISECONDS, and I want to convert it into NANOSECONDS.
unit.convert(trigger - System.nanoTime(), NANOSECONDS);
This line means trigger - System.nanoTime() is a value in NANOSECONDS, and I want to convert it into unit value.
A DelayQueue sample code is attached.
- DelayQueueDemo.zip (1.2 KB)
- 下载次数: 12
发表评论
-
javadoc for Cyclic Barrier
2009-04-24 12:48 904java.util.concurrent.CyclicBarr ... -
Count Down Latch example code
2009-04-22 10:38 1155Key point : 1) 1 task is co ... -
3 ways to break dead lock
2009-04-21 17:30 7621) supply special resources. ... -
Blocking Queue Usage
2009-04-20 11:21 8333 implementations: LinkedBlocki ... -
The usage of Lock and Condition
2009-04-18 12:31 1069//: concurrency/waxomatic2/WaxO ... -
Re entrantLock usage
2009-04-15 17:15 1320a thread can be really interru ... -
new interrupt in java5
2009-04-15 12:08 658In Java 5, Thread.interrupt() i ... -
interrupt
2009-04-15 10:57 8171) Each thread has a boolean in ... -
Executor Service Usage
2009-04-14 18:18 894ExecutorService exec = Executor ... -
Thread Local usage
2009-04-14 17:46 817ThreadLocal usage – from Javado ... -
Timer TimerTask usage
2009-04-14 12:03 724Timer typical usage new Tim ... -
wait, notify及线程通讯机制
2009-02-26 22:42 8501) wait(), notify() 方法被调用的时候,只要 ... -
Java Thread programming basical knowledge
2009-02-26 22:40 1089yield() : Give a hint to the th ... -
Count Down Latch explanation
2008-10-02 10:29 957Very important paragraph on how ... -
Scheduled Executor Service
2008-07-22 11:27 1107Executor can return Executor, E ... -
Executor usage
2008-07-22 11:04 903Executor is used to arrange thr ... -
Callable Usage
2008-07-22 10:24 933The important thing need to loo ...
相关推荐
### 反馈延迟对传输波束成形性能的影响 #### 摘要解析与扩展 在现代通信系统中,特别是多天线系统中,传输波束成形(Transmit Beamforming, TB)作为一种有效的对抗多径衰落的技术,其性能受到了广泛的关注。...
rabbitmqadmin declare queue name=my_delayed_queue rabbitmqadmin declare binding source=my_delayed_exchange destination=my_delayed_queue routing_key=* ``` 4. 发布延迟消息:发布消息时,添加`x-delay`...
channel.queue_bind(queue='delayed_queue', exchange='delayed_exchange', routing_key='') # 发布延迟消息 delay_time = 60 * 1000 # 1分钟延迟 props = pika.BasicProperties(delivery_mode=2, headers={'x-...
rabbitmqadmin declare binding source=delayed_exchange destination=my_queue routing_key=my_routing_key ``` 4. **消费消息**:消费者可以从`my_queue`队列中正常接收延迟后到达的消息。 **应用场景** 1. **...
channel.queue_bind(exchange='delayed_exchange', queue=queue_name, routing_key='') def callback(ch, method, properties, body): print(f'Received message: {body} after delay') channel.basic_consume...
在这段代码中,`my_delayed_exchange`是我们声明的延时交换机,`x-delay`属性设置为30000毫秒(即30秒)。 需要注意的是,延时交换机不支持所有类型的绑定,目前仅支持Direct和Topic类型的路由键。此外,由于延迟...
2. X_DELAYED_TYPE属性:在创建延迟交换机时,需要设置`x-delayed-type`参数为普通交换机类型(如`direct`、`topic`等),这使得延迟交换机具备了普通交换机的功能,同时添加了延迟特性。 二、RabbitMQ 3.9.0版本新...
在这个压缩包文件"rabbitmq_delayed_message_exchange-20171215-3.6.x.zip"中,我们关注的核心是延迟消息交换(Delayed Message Exchange)功能,这是RabbitMQ在3.6.x版本中引入的一个重要特性。该功能允许用户设置...
channel.queue_bind(queue=queue_name, exchange='delayed_exchange', routing_key='') ``` **应用场景** 1. **订单超时处理**:在电商系统中,可以使用延时队列来处理未支付的订单,比如在30分钟后自动取消未支付...
channel.basic_publish(exchange='delayed_exchange', routing_key='queue_name', body='Hello, World!', properties=props) print(" [x] Sent 'Hello, World!'") connection.close() ``` 这里的“x-delay”头就是...
在这个场景中,我们关注的是`rabbitmq_delayed_message_exchange-20171201-3.7.x.ez`插件,这是一个用于RabbitMQ的特殊交换机类型,它允许我们延迟消息的投递,即在特定时间后才将消息发送到队列。 **延迟消息...
xx state variable and delayed state variables columnwise par list of parameter values nx empty or list of requested state-derivatives (numbers of delay or zero) np empty or list of requested ...
延时队列的实现原理主要依赖于两个核心概念:交换机(Exchange)和队列(Queue)。交换机负责根据预设的路由规则将消息分发到相应的队列。在这个插件中,我们可能会使用一种特殊的交换机类型,如"x-delayed-message...
RabbitMQ延迟队列插件,即rabbitmq_delayed_message_exchange-3.8.0,是一个针对RabbitMQ消息代理的扩展,旨在提供一种机制,使得消息能够在特定延迟后才被投递到相应的队列。这个功能在很多业务场景中非常有用,...
rabbitmq_delayed_message_exchange-20171215-3.6.x.zip 是一个为RabbitMQ设计的插件压缩包,旨在为RabbitMQ添加延迟消息交换功能; 以下是几个典型的使用场景示例: 订单超时处理: 当用户下单后未及时支付时,...
安装一个插件即可:https://www.rabbitmq.com/community-plugins.html ,下载rabbitmq_delayed_message_exchange插件,然后解压放置到RabbitMQ的插件目录...rabbitmq-plugins enable rabbitmq_delayed_message_exchange
delay-free system. Two delicate performance index functions are defined for these two systems. It is shown that the performance index functions are equivalent and the optimal consensus control problem...
截止2021.08.19日适配官网最新版rabbitmq3.9.3的消息延时队列插件,包内含有rabbitmq_delayed_message_exchange-3.9.0.ez格式、zip格式、tar.gz格式安装包任你选择~~