Home » Tag Archives: Concurrency (page 6)

Tag Archives: Concurrency

Experiment with ConcurrentHashmap

java-logo

I am investigating a memory issue in one of my recent projects where data is kept in memory for fast access, but the memory footprint of application is very high. This application was heavily using CHM(i.e Concurrenthashmap), so no brainier guess was required that CHM was the issue. I did a memory profiling session to find how much memory CHM was really taking. ...

Read More »

Five advanced Java Synchronizers you probably don’t know

java-logo

Besides the common synchronize which is based in the lock bit that every Java object has, you have more sophisticated synchronizers in java, such as: Semaphore – Use the concept of a permit to indicate a max number of allowed threads in a place. When you use the value 1, the behavior its similar to synchronize, also called binary semaphore. There is however a big difference ...

Read More »

Java 8: CompletableFuture in action

java-logo

After thoroughly exploring CompletableFuture API in Java 8 we are prepared to write a simplistic web crawler. We solved similar problem already using ExecutorCompletionService, Guava ListenableFuture and Scala/Akka. I choose the same problem so that it’s easy to compare approaches and implementation techniques. First we shall define a simple, blocking method to download the contents of a single URL:   ...

Read More »

Java 8: Definitive guide to CompletableFuture

java-logo

Java 8 is coming so it’s time to study new features. While Java 7 and Java 6 were rather minor releases, version 8 will be a big step forward. Maybe even too big? Today I will give you a thorough explanation of new abstraction in JDK 8 – CompletableFuture<T>. As you all know Java 8 will hopefully be released in ...

Read More »

Synchronising Multithreaded Integration Tests revisited

java-interview-questions-answers

I recently stumbled upon an articleSynchronising Multithreaded Integration Tests on Captain Debug’s Blog. That post emphasizes the problem of designing integration tests involving class under test running business logic asynchronously. This contrived example was given (I stripped some comments):               public class ThreadWrapper { public void doWork() { Thread thread = new Thread() { ...

Read More »

Why a synchronized StringBuffer was never a good idea

java-logo

Introduction StringBuffer is a synchronized class for mutable strings.  The main problem with making it synchronized is that It was usually used as a local variable so making it synchronized just made it slower. It was never a good idea to use it in a multi-threaded way.  This problem is that developers assumed that methods which used StringBuffer were themselves ...

Read More »

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 »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close