Archive for the 'java' Category

Having “fun” with JSR-303 Beans Validation and OSGi + Spring DM

Most Java standards are implemented using an api jar and an concrete implementation jar. The API constists maninly of interfaces but a class that looks up the default implementation. This lookup normally happens by trying to load a specific resource bundle which is located in the implementation jar. This can lead to “interesting” classloader problems when used with OSGi and Spring DM specifically
Read more »

Detached Service Methods with Spring AOP

In a typical spring based server application there is a service layer responsible for infrastructure tasks and communication with the clients. Service methods can be long running and execution would normally block the user-interface. Putting the client side end of the call in a thread solves the blocking but leaves the network connection open while the server side of the call is active. This can lead to all sorts of time-out issues and seems to be the wrong end to fix the problem .

Using spring AOP it is remarkably easy to declaratively enable service methods to execute detached from the regular call context.

The Goal

@DeferredExecution
public myServiceMethod() throws DeferredExecutionException {
}

This method would execute with the following sematics:

  1. The regular method call is wrapped in a thread
  2. The thread is executed
  3. If the thread does not finish within x seconds, raise a checked exception
  4. If it does finish in time, return the result of the method

This way clients of this method are forced to handle detached execution (i.e. show a progress dialog querying the server) and the client side of the call not langer lasts longer than a set time.
Read more »