• Search and lock in a single query.
    Feb 11, 2010

    There is a task in the current project I am working with, which is getting a product (that could be anything, in our case it was products users had to do some work with) for a user logged in to the system, and simultaneously locking it so that no other user can access it. While my first idea about solution was having a synchronized piece of code which would first make a query to search for a product, and another query to lock it in the database. Note that we are using database table for locking.

    Read more...
  • MySQL update bug in Ubuntu, MySQL clean install with --purge parameter to apt-get
    Feb 11, 2010

    Today while updating my Ubuntu installation(Ubuntu 9.10 Karmic Koala) , mysql package also had an update, but after installation it refused to start. Version of package failing to install was mysql-server 5.1.37-1ubuntu5. Looking around I found out that problems with mysql updates occur quite frequently, and what usually helps is a fresh install.

    Read more...
  • java.util.Arrays.asList(T... a) method returns an immutable ArrayList!
    Feb 10, 2010

    It does, to my biggest surprise, I got UnsupporttedOperationException when I tried to add objects into the list I received via invoking a call to Arrays.asList(). And even bigger surprise that looking at the stack trace I found out that the exception is thrown from the add() method of java.util.AbstractList.

    Read more...
  • Enhanced (or not so) for loop and ConcurrentModificationException while iterating over the List
    Feb 9, 2010

    Today I was writing a code that would loop over an ArrayList and if some condition occurs remove it from the collection. It looked similar to this:

    Read more...
  • Java identifier names and currency character(s).
    Feb 7, 2010

    During studying for SCJP I came to the topic of valid characters for identifiers, and what caught my attention was that its not only $ character is meant as currency character, but also €, £ and probably all other currency signs. So valid identifiers are characters, numbers, underscore and currency characters. And also we must not forget that number cannot be the first character of the name of an identifier.

    Read more...
  • Servlet loading on start-up
    Jan 13, 2010

    I recently had a task where I had to make a servlet which would store a configuration data for a large GWT project. Writing a servlet that would read everything from web.xml file, I later realized that servlet needs to be initialized before it has values from web.xml, and Tomcat initializes it only when the request is made towards it. Looking through various solutions, I found out that the easiest way would be telling Tomcat to initialize it on load, or on startup, rather than initializing it on first request. It can be achieved by simply adding <load-on-startup>1</load-on-startup> between <servlet> tags in web.xml file. Overall picture looks something like this:

    Read more...
  • Focusing on elements in GWT 1.7 with setFocus()
    Dec 8, 2009

    I found today that doing setFocus on elements may not work properly all the time, due to thread issue. Solution to this problem would be using DeferredCommand class with passing a new Command to it. So instead of

    Read more...

subscribe via RSS