Quantcast
Channel: Scratch Where It's Itching
Browsing all 73 articles
Browse latest View live

AutoCloseable when not available

On his blog, Brian Oxley shows a neat way in JDK 8 to use non AutoCloseable object having a close-like method in a try with resources construct, using the new method references. For those of us who are...

View Article


Get Simple Class Name

You probably heard of one method of Class that give the simple name of the class, without all the packages. Even if you hadn't, you probably know a simple way to get the sub-String following the last...

View Article


FIFO Stack and LIFO Queue

Recently, I found this class in one of our applications:publicclass FIFOStack extends Vector {publicsynchronized Object push(Object o) { add(o);return o; } publicsynchronized Object pop() {if...

View Article

Why don't I know my disk is full?

We had this interesting problem lately, that an application had a corrupted file after a disk got full. The strange thing was that the app did not know that the disk was full. We were expecting an...

View Article

Capital Date Mistake

Here is a small piece of code. Can you tell what it prints? SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2014);...

View Article


Java 8 Compilation Strangeness

A colleague of mine (thanks Clement) showed me some strange issues his team met when they decided to move their project to Java 8. These issues did not appear while compiling with Eclipse, but showed...

View Article

Autoclose Lock

I was just wondering if there is a difference between the classic: lock.lock();try { //I have the lock! } finally { lock.unlock(); } And the Autocloseable version: lock.lock();try (AutoCloseable auto =...

View Article

Thou Shall Close Thy Streams

You should always close your IO streams. Said like this, it sounds obvious. But in the light of some new Java 8 features, it took me some time to get around it.I needed to write a small method for...

View Article


Boolean Parsing Fest

A small gem I found the other day: String value = ...boolean booleanValue = Boolean.valueOf(value.toLowerCase()).booleanValue(); A lot of useless stuff: toLowerCase is useless because the Boolean class...

View Article


Lambda Before Switch

We had this method that was doing the same thing several times in a row. Here is a simplified version:void resolveAll() { a = resolveA();if (a == null) states.remove(State.A);else states.add(State.A);...

View Article

Collectors.toMap does not like null

Some map accept null values, some don't. How do you know? You usually take a look in the javadoc. But what about maps created by streams through the Collectors.toMap? The javadoc does not say. So I...

View Article

See you at Devoxx Paris

I'm in! The quickie I proposed to the Devoxx Paris comitee was accepted. It is called "The Thread Awakens". Maybe there were some Star Wars fan in the decision process?

View Article

Log content of SOAP message

It's probably all over StackOverflow, but lately I had to log the XML content of SOAP messages for debugging. I did it this way:publicvoid connect() { Service service = ... List<Handler>...

View Article


Java 8 might kill doclint

Since Java 8, javadoc doclint became a lot stricter. Up to now, we had some warnings here and there. But since we moved to Java 8, our Jenkins releases are failing because doclint would throw HTML...

View Article

Image may be NSFW.
Clik here to view.

Rocket Anti-Pattern

At my presentation at Devoxx Paris this year, The Thread Awakens, I introduced several Patterns related to multithreading. Since it was a quickie, I had only 15 minutes to talk about 15 Patterns. That...

View Article


Image may be NSFW.
Clik here to view.

Paratrooper Model

In my previous entry, I was describing the Rocket Anti-Pattern, where one thread would handle too much work across several application layers, leading to communication buffer overflow and message...

View Article

Image may be NSFW.
Clik here to view.

Marsupilami Pattern

In my previous entry, I described the Paratrooper Model, where each application layer would have its own thread pool for handling data. And the way to implement that is to use the Marsupilami...

View Article


Image may be NSFW.
Clik here to view.

Indian Train Anti-Pattern

Last time, I talked about the Marsupilami Pattern, where we introduced queues to transport data between application layers.Now you’ve been using these queues for some time, conveying all sorts of data,...

View Article

Image may be NSFW.
Clik here to view.

Indiana Jones Pattern

In my previous entry, I presented the Indian Train Anti-Pattern, where we added without discrimination data to be handled on our queues, leading to overcrowded queues.One possibility to alleviate the...

View Article

Image may be NSFW.
Clik here to view.

Hamburger Pattern

Last time, I introduced the Indiana Jones Pattern, where you would filter your messages in order to send less data on your overcrowded queue.Another way to reduce the number of messages is to use the...

View Article
Browsing all 73 articles
Browse latest View live