Tuesday, November 6, 2012

semaphores

to have a look later

http://javapapers.com/core-java/semaphores-using-java/

http://www.javacodegeeks.com/2011/09/java-concurrency-tutorial-semaphores.html

what I am going to use
is
java.util.concurrent.locks.Lock

with tryLock() and lock()

Tuesday, July 24, 2012

java - copy directory


surprisingly copy file in Java <7 copies a file, not a directory

    // Copies all files under srcDir to dstDir.
    // If dstDir does not exist, it will be created.
    public void copyDirectory(File srcDir, File dstDir)
        throws IOException
    {
        if (srcDir.isDirectory())
        {
            if (!dstDir.exists())
            {
                dstDir.mkdir();
            }

            String[] children = srcDir.list();
            for (int i = 0; i < children.length; i++)
            {
                copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
            }
        }
        else
        {
            // This method is implemented in Copying a File
            // copyFile(srcDir, dstDir);
        }
    }

java - Arrays.asList returns not modifiable AbstractList


Arrays.asList: Returns a fixed-size list backed by the specified array.
so, when calling add() or remove() to the result of Arrays.asList - java.lang.UnsupportedOperationException is thrown


to convert an array to a modifiable List use:
T[] data;

List<T> list = new LinkedList<T>(Arrays.asList(data));

Thursday, April 19, 2012

Solr

http://lucene.apache.org/solr/