Home » Tag Archives: Concurrency (page 7)

Tag Archives: Concurrency

Inadvertent Recursion Protection with Java ThreadLocals

java-logo

Now here’s a little trick for those of you hacking around with third-party tools, trying to extend them without fully understanding them (yet!). Assume the following situation: You want to extend a library that exposes a hierarchical data model (let’s assume you want to extend Apache Jackrabbit) That library internally checks access rights before accessing any nodes of the content ...

Read More »

Detecting Java Threads in Deadlock with Groovy and JMX

groovy-logo

Unfortunately, Java applications taking advantage of multiple threads can at times run into the dreaded deadlock condition. Fortunately, the Java Platform makes deadlock detection relatively easy. In fact, the built-in (since J2SE 5) ThreadMXBean (a PlatformManagedObject exposed via JMX) makes this information available to any client that ‘speaks JMX‘ via the findDeadlockedThreads() and findMonitorDeadlockThreads() methods. General ‘JMX clients’ such as ...

Read More »

Advanced ListenableFuture capabilities

java-interview-questions-answers

Last time we familiarized ourselves with ListenableFuture. I promised to introduced more advanced techniques, namely transformations and chaining. Let’s start from something straightforward. Say we have our ListenableFuture<String> which we got from some asynchronous service. We also have a simple method:               Document parse(String xml) {//... We don’t need String, we need Document. One ...

Read More »

My Custom Thread Pool Executor in Java

java-logo

ThreadPoolExecutor is a feature added by java concurrent api to maintain and reuse threads efficiently , so that our programs don’t have to worry about creating and destroying threads and focus on the core functionality. I have created a custom thread pool executor to get better understanding of how thread pool executor would work . Functionality : It maintains a ...

Read More »

ListenableFuture in Guava

java-logo

ListenableFuture in Guava is an attempt to define consistent API for Future objects to register completion callbacks. With the ability to add callback when Future completes, we can asynchronously and effectively respond to incoming events. If your application is highly concurrent with lots of future objects, I strongly recommend using ListenableFuture whenever you can. Technically ListenableFuture extends Future interface by ...

Read More »

Implementing custom Future

java-interview-questions-answers

Last time we learned the principles behind java.util.concurrent.Future<T>. We also discovered that Future<T> is typically returned by libraries or frameworks. But there is nothing stopping us from implementing it all by ourselves when it makes sense. It is not particularly complex and may significantly improve your design. I did my best to pick interesting use case for our example. JMS ...

Read More »

java.util.concurrent.Future basics

java-logo

Hereby I am starting a series of articles about future concept in programming languages (also known as promises or delays) with a working title: Back to the Future. Futures are very important abstraction, even more these day than ever due to growing demand for asynchronous, event-driven, parallel and scalable systems. In the first article we’ll discover most basic java.util.concurrent.Future<T> interface. ...

Read More »

Java concurrency: the hidden thread deadlocks

java-logo

Most Java programmers are familiar with the Java thread deadlock concept. It essentially involves 2 threads waiting forever for each other. This condition is often the result of flat (synchronized) or ReentrantLock (read or write) lock-ordering problems.                 Found one Java-level deadlock: ============================= "pool-1-thread-2": waiting to lock monitor 0x0237ada4 (object 0x272200e8, a java.lang.Object), ...

Read More »

Synchronising Multithreaded Integration Tests

java-interview-questions-answers

Testing threads is hard, very hard and this makes writing good integration tests for multithreaded systems under test… hard. This is because in JUnit there’s no built in synchronisation between the test code, the object under test and any threads. This means that problems usually arise when you have to write a test for a method that creates and runs ...

Read More »

How to shoot yourself in foot with ThreadLocals

java-logo

It will start nicely. Like most of the stories. You discover a new concept and are amazed by it’s powers. And then equipped with this new hammer suddenly everything starts to look like a nail. From what we have experienced in past months, java.lang.ThreadLocal makes one hell of a hammer. I guess it all boils down to the very concept ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.