All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.funtom.util.concurrent.ReadWriteSynchronizedExecutor Maven / Gradle / Ivy

There is a newer version: 0.2
Show newest version
package io.funtom.util.concurrent;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Supplier;

/**
 * An Executor which executes tasks on the caller thread.
 * 

* Calls to readExecute(...) methods: *

  • Never lock each other
  • *
  • Have the same memory semantics as locking and unlocking the read lock of a java.util.concurrent.lock.{@link ReadWriteLock}
*

* Calls to writeExecute(...) methods: *

  • Never overlaps with any other calls to execute methods
  • *
  • Have the same memory semantics as locking and unlocking the write lock of a java.util.concurrent.lock.{@link ReadWriteLock}
*

* Calling threads might be suspended. */ public final class ReadWriteSynchronizedExecutor { private final SynchronizedExecutor readExecutor; private final SynchronizedExecutor writeExecutor; public ReadWriteSynchronizedExecutor() { ReadWriteLock lock = new ReentrantReadWriteLock(); readExecutor = new SynchronizedExecutor(lock.readLock()); writeExecutor = new SynchronizedExecutor(lock.writeLock()); } public void readExecute(Runnable task) { readExecutor.execute(task); } public R readExecute(Supplier task) { return readExecutor.execute(task); } public void writeExecute(Runnable task) { writeExecutor.execute(task); } public R writeExecute(Supplier task) { return writeExecutor.execute(task); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy