Skip to content

An attempt to implements j.u.c whereby other alogrithms

Notifications You must be signed in to change notification settings

jlusdy/concurrent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Concurrent

An attempt to implements j.u.c whereby other alogrithms

Getting Started

Pre-requirement

  • JDK 6 +

Installation

git clone https://github.com/coderplay/concurrent.git
mvn clean package

Examples

FastArrayBlockingQueue

    final int BUFFER_SIZE = 1024 * 8;
    final long ITERATIONS = 1000L * 1000L * 10L;
    final BlockingQueue<Long> queue =
        new FastArrayBlockingQueue<Long>(
            // producer strategy 
            new SingleThreadedClaimStrategy(BUFFER_SIZE),
            // consumer strategy
            new SingleThreadedWaitStrategy()); 
    Runnable consumer = new Runnable() {
      @Override
      public void run() {
        try {
          for (long l = 0; l < ITERATIONS; l++)
            queue.take().longValue();
        } catch (InterruptedException ie) {
        }
      }
    };

    Runnable producer = new Runnable() {
      @Override
      public void run() {
        try {
          for (long l = 0; l < ITERATIONS; l++)
            queue.put(Long.valueOf(l));
        } catch (InterruptedException ie) {
        }
      }
    };

    new Thread(consumer).start();
    new Thread(producer).start();

About

An attempt to implements j.u.c whereby other alogrithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published