Posts

Showing posts from May, 2010

Tomcat Window Service

Image
Tomcat allows developer to set tomcat instance as window service. You can install, update or remove the service base on the following document.
http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html
Most of the time, we are concerned about JVM options in Tomcat window service. Install, update and delete is not an issue, these actions can be easily done by //IS //US and //DS.
Sometime, you may face problems such as "How to remove 1 JVM options from the current JVM options", or "I cannot start tomcat server after updating JVM options"
You can manually modify Tomcat JVM option at the registry key "HLM\Software\Apache Software Foundation\Procrun 2.0\\Parameters\
All you need is to reset the Options registry key. Also, you can tune JvmMs and JVMMx here too.

Why is Java limited to 1.5MB process size on Win XP?

In general, the reason is“The reason we need a contiguous memory region for the heap is that we have a bunch of side data structures that are indexed by (scaled) offsets from the start of the heap. For example, we track object reference updates with a "card mark array" that has one byte for each 512 bytes of heap. When we store a reference in the heap we have to mark the corresponding byte in the card mark array. We right shift the destination address of the store and use that to index the card mark array. Fun addressing arithmetic games you can't do in Java that you get to (have to :-) play in C++.Usually we don't have trouble getting modest contiguous regions (up to about 1.5GB on Windohs, up to about 3.8GB on Solaris. YMMV.). On Windohs, the problem is mostly that there are some libraries that get loaded before the JVM starts up that break up the address space. Using the /3GB switch won't rebase those libraries, so they are still a problem for us.We know how t…

Restore MBR for XP and Remove Ubuntu

This works for removing Ubuntu OS from a dual boot system.In general, you have to restore your MBR and reformat your Ubuntu partitionTo restore your MBR: 1. Insert the Windows Setup CD into the CD or DVD tray on your computer. 2. Restart your computer. 3. Hit Enter to reboot from the Windows CD when prompted to do so. 4. Type “R” and hit Enter in Windows Setup to enter the RecoveryConsole. The Recovery Console will appear and list the Windows OSson your machine. 5. Select the number corresponding to the Windows installation youwish to boot into. For most people this will be a “1”. (In someversions of the Recovery Console the installations will benumbered. In others, you will have to deduce the installationnumber from the order of priority in the list.) 6. Windows will prompt you for an Administrator password.Try your Administrator password or, if your Administrator password does notwork, hit Enter. 7. At the Windows prompt, type “fixmbr”. 8. Type “exit” to restart the…

IllegalMonitorStateException

Base on JavaDoc, IllegalMonitorStateException is thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor.
This can happens when you perform notify, notifyAll, wait method for an object, especially, when you are trying to perform cross thread notify and wait operation.
The way to solve this issue is to surround the object to be notified or wait with synchornized block

synchronized (obj) { obj.wait(); }

TreeSet, TreeMap and Comparator

Comparator provides a compare method to provide total order to TreeSet and TreeMap. Details can be found in http://java.sun.com/javase/6/docs/api/java/util/Comparator.html
When writing compare method, note the following
1. A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. 2. It uses modified mergesort as the underlying sorting mechanism. 3. Keep the compare method simple. 4. Remove, Add, Contain, etc.. method will use Comparator's compare method for comparison. If you compare is wrong, you may end up with logic error when performing remove, add or contain action with TreeSet/TreeMap.