Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

util



The util package contains additional classes which work with the Java util package.

LauncherUtils

Main Article: LauncherUtils

The LauncherUtils class allows to parse an array of argument / values usually returned in the main static method of a class.

The arguments can have one of the following pattern:
      key1 prop1 key2 prop2 ...
or
      key1=prop1 key2=prop2 ...
It is even possible to mix the two patterns such as:
      key1 prop1 key2=prop2 ...
If the value for the key is not set, then a (key, value) will be added with an empty String as value
      key2= -key3 -key4=value4

SingletonList

The SingletonList class is a list which is guaranteed to have only one element. As for any List, it is possible to iterate through this List, but of course the iteration will stop after the first element.

ConcurrentHashSet

The ConcurrentHashSet class is a thread-safe Set implementation, which do not entail locking.

SoftHashMap

The SoftHashMap class is a simple HashMap which uses SoftReference values.

BlockingTimerTask

The BlockingTimerTask class is a TimerTask for which is it possible to block the execution in the calling Thread until the timer has elapsed.

Contrary to the TimerTask class, the method to implement when the timer has elapsed is BlockingTimerTask.runImpl() rather than BlockingTimerTask.run() which can not be overriden.

The BlockingTimerTask.await() method will block in the calling Thread until the timer is run (so after the timer has elapsed). However if you don't call this method, the BlockingTimerTask will work just like a TimerTask

Cancelling the timer will also unblock the calling Thread. However as can be expected you will only be able to call it in another Thread.

You must be aware that if you have a periodic timer, the BlockingTimerTask.await() method will block for each iteration of the timer loop, which might not be what you want.

For example:
   BlockingTimerTask instance = new BlockingTimerTask() {
      public void runImpl() {
        System.out.println("Done!");
      }
   };
   Timer timer = new Timer();
   timer.schedule(instance, 1000);
   try {
      instance.await();
   } catch (InterruptedException ex) {
   }

Categories: packages | util

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences