Posts of the month: december 2012


PHP's nl2br equivalent in JSPs

Some of PHP’s built-in functions can be quite handy. One of these is nl2br, which transforms newlines (\n and other variants) into HTML line breaks (<br>) — more precisely, it puts a <br> before each newline.
It has been used, and sometimes is still used, when echoing a CLOB on a webpage.

Actually, this function is no longer necessary: with the CSS property white-space you can do the same on the client-side in a neat and efficient way. However, this post is just an example on how to create something resembling PHP’s built-in functions using the instruments of Java EE. Read more...

Tags: java, php

Wait until any thread terminates

In Java programming, it’s quite common to start a pool of threads and wait for all threads to terminate: this can be achieved in several ways, the most simple of which is the one of “joining” all the threads.

However, there are situations in which you may want to wait for any thread to terminate, i.e. stop waiting when at least one thread terminates — and abort all the others.
You may want to have such a behaviour when you have several threads working on the same problem (for example, a search problem) and you want to stop all threads when at least one of them finds a solution. Read more...

Tags: java
Fork me on GitHub