18

I wish I can get the simplest possible example code, which will show how to use LMAX disruptor(http://code.google.com/p/disruptor/).

Unfortunately every piece of code is out of date. Does someone know, where can I found small and up to date howto (preferable without DSL)?

Dejwi
  • 4,393
  • 12
  • 45
  • 74

5 Answers5

22

Here is a simple, runnable, example of how to use the Disruptor library. Example is written in Java using version 2.10.4 of the Disruptor library.

https://github.com/trevorbernard/disruptor-examples

Trevor Bernard
  • 992
  • 10
  • 13
  • excellent example. i got caught out passing the ValueEvents between threads not realising that they are recycled by the buffer. I have sent you a pull request with some comments to that effect so that folks can learn from my mistake. – simbo1905 Feb 19 '13 at 23:18
15

you can see the example here.

http://code.google.com/p/disruptor/wiki/CodeExampleDisruptor2x

I have done a simple example by using the above wiki. hope this helps you.

weima
  • 4,653
  • 6
  • 34
  • 55
  • 2
    That example code is outdate, the ValueEntry can not find in Disruptor 2.10, where can find the newest Disruptor example code, if 2.8+ is best! Thanks! – LiuTiger Aug 30 '12 at 02:31
  • ValueEvent is not a disruptor library class. It your class which is use to "hold" your actual event or message. The event factory is then use to pre-create instances of ValueEvent and put on the ring buffer. When your message or event comes in, you get one of the instances created, you set your message on it and say publish. Then ring buffer dispatches it to the handlers. – Abe Dec 18 '12 at 00:00
11

There is an official sample application on github now: Getting-Started

2

Sharing an example with multiple publishers and chained handlers, this uses their latest available dsl api format https://web.archive.org/web/20140325163503/http://vijayrc.com/vectorclocks/post/thread3

[EDIT 2022-08-29]:

Link was outdated and is not active. Since the answer is good,redirecting to answer via waybackmachine.

Bharath M Shetty
  • 30,075
  • 6
  • 57
  • 108
0

I have shared example here, I hope it helps.

This question might be duplicate of

Disruptor helloworld example

Community
  • 1
  • 1
Rohit Sachan
  • 1,178
  • 1
  • 8
  • 16