Thursday, January 24, 2008

Hot Code Changes

Hot Code Changes

ClassLoaders let you modify code on the fly without shutting down an application. New code is loaded with Class.forname. It creates new versions of the objects by reloading the classes for the objects with a ClassLoader. You then have both old and new versions of the same object, both with the same name, but with different data and different code. From the JVM’s point of view, a class loaded with a new ClassLoader is a different animal entirely from the one loaded with the standard ClassLoader even if the classes have the same name. You can manipulate both old an new objects with a common interface.

With a new ClassLoader, you can load a different version of a class. The old objects continue to use the old code. New objects use the new code. A given ClassLoader can load a given class only once. There is no need to unload a class. When the objects using it are no longer referenced, the class object itself, along with the code, will be garbage collected. The same classes, loaded by different class loaders are considered distinct classes. They are not instanceofs each other!

You will have to instantiate a new ClassLoader every time you have a new generation of classes. You can load all the replacement classes of a generation with the same ClassLoader. However, when you want to replace the replaced classes, you need a yet another new ClassLoader. You can do this with multiple instances of the same ClassLoader. You only need to write one ClassLoader, perhaps not even one, not one for each generation.

Have a look at the java.net.URLClassLoader. You may find for your given problem you don’t even have to write whole new ClassLoader, just instantiate one of Sun’s.

http://mindprod.com/jgloss/classloader.html

How to unload Java Class

How to unload Java Class: "I have been asked this question several times. Recently Xyling asked the same question in his blog. So I thought a simple explanation may be in order.

To unload a class you have to create a custom classloader and load the class using it. Tomcat does it and so does JRun. You can look in Tomcat code for an example.

After you are done with the class you need to release all references to the class as well as to the class loader by reassigning the variables or setting them to null.

Then either wait for System.gc() to unload the class or you call it directly in a loop till no more bytes can be freed. however normally calling it twice does the trick.

Note: You cannot unload a single class. You have to unload the classloader along with it. So obviously System classloader is not the suitable for this task.

Note 2: This is how JSP pages are reloaded dynamically everytime you change the code. And yes that is why first time takes much longer to load then subsequent times."

Saturday, December 08, 2007

Access Mac OS X Sharing from Vista

I purchased a new laser printer and use my Mac Mini as the printer server.

My Windows XP laptop can access it. However, Vista desktop got trouble. Here is the solution googled that works:

  1. Click Windows Visa Start Orb
  2. In search box, type "regedit" and return
  3. Once regedit opens, click File -> export to make a backup copy
  4. Navigate to ComputerHKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa.
  5. n the right pane, right-click the "LmCompatibilityLevel" key and select "modify"
  6. Change the value from 3 to 1
  7. Exit regedit and you should now be able to properly authenticate to your Mac OS X (or other Samba) share.

Monday, September 17, 2007

Service Group Problems with Apache Axis2

Recently, I am doing web services programming with Apache Axis2. I perform several builds with the target stock.aar (every time, the content of services.xml is different). The deployment are successfully all the times. However, when I try to access the web service using a client, I receive the following error:

... StockQuoteService_Jack2, which is invalid. It does not belong to the stock service group ...

To my understanding, a service group is a .aar file - all the web services contained in the .aar belong to the same service group and the group name is the file name without extension.

To solve the problem, I restart my Tomcat. It seems that the problem was caused due some caching problems of Axis2.

Tuesday, August 28, 2007

Compile Asprise OCR on Solaris

Reference article: Hint: How to install gcc on Solaris (easiest way possible - I think)

Actual procedure:

A. Download all the required software:

$ cd installer/
$ ftp ftp.sunfreeware.com
ftp> cd pub/freeware/i386/10/
prompt
mget gzip*
mget make*
mget gcc*
ftp> quit
$ ls
gcc-3.3.2-sol10-intel-local.gz gzip-1.3.5.10-sol10-x86-local
gcc-3.3.6-sol10-intel-local.gz make-3.80-sol10-intel-local.gz
gcc-3.4.6-sol10-x86-local.gz make-3.81-sol10-x86-local.gz
gzip-1.3.5-sol10-intel-local
$ su
# bash
# PATH=$PATH:.:/usr/local/bin
# pkgadd -d gzip-1.3.5-sol10-intel-local
# gunzip -d make-3.81-sol10-x86-local.gz
# pkgadd -d make-3.81-sol10-x86-local
# gzip -d gcc-3.4.6-sol10-x86-local.gz
# pkgadd -d gcc-3.4.6-sol10-x86-local
Do you want to install these conflicting files [y,n,?,q] y
# g++ -v
Reading specs from /opt/bin/../lib/gcc/i386-pc-solaris2.10/3.4.6/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --enable-shared --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.4.6
# java -version
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Server VM (build 1.5.0_07-b03, mixed mode)
# ls /usr/java/include/
jawt.h jni.h jvmpi.h solaris
jdwpTransport.h jvmdi.h jvmti.h
# ls /usr/java/include/solaris/
jawt_md.h jni_md.h
# mkdir java-evaluation
# mkdir java-licensed
# ./buildEvaluation.sh
# ./buildLicensed.sh
# cd java-evaluation/
# chmod a+x *.sh
# ./runDemo1.sh

--- A general sample with both characters and barcodes ---

Welcome to Asprise OCR v2.1 Demo!

Trying to perform OCR on image: /export/home/asprise_dev/ocr/java-evaluation/sample-images/ocr.gif
Exception in thread "main" java.lang.UnsatisfiedLinkError: /export/home/asprise_dev/ocr/java-evaluation/libAspriseOCR.so: ld.so.1: java: fatal: libstdc++.so.6: open failed: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at com.asprise.util.ocr.OCR.loadLibrary(OCR.java:247)
at com.asprise.util.ocr.OCR.(OCR.java:56)
at com.asprise.util.ocr.demo.Demo.main(Demo.java:51)

# ftp ftp.sunfreeware.com
ftp> cd pub/freeware/i386/10/
ftp> mget libgcc*
# gzip -d libgcc-3.4.6-sol10-x86-local.gz
# pkgadd -d gcc-3.4.6-sol10-x86-local
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH:/usr/local/lib
java -classpath .:aspriseOCR.jar:demo.jar com.asprise.util.ocr.demo.Demo sample-images/ocr.gif

=== ASPRISE OCR SDK EVALUATION ===

1) For licensing information, visit: http://asprise.com/product/ocr
2) This evaluation version replaces all recognized 'q' and 'x' occurrences with stars ('*').

[123456789012]
Asprise OCR
Speed. Accuracy.


UPDATE:

On a Solaris 10 x86, after install GCC, I run g++ -v, and it reports error about missing iconv. To fix it:

Go the same FTP folder:
#mget libiconv*
#gzip -d libiconv-1.11-sol10-x86-local.gz
#pkgadd -d
libiconv-1.11-sol10-x86-local







Labels: , , , , , , , ,

Tuesday, May 22, 2007

Jakarta JSTL Library

Jakarta JSTL Library

To use the Standard Taglib from its Jakarta Taglibs distribution, simply copy the JAR files [jstl.jar & standard.jar] in the distribution's 'lib' directory to your application's WEB-INF/lib directory.

jstl.jar - JSTL API classes
standard.jar - Standard Taglib JSTL implementation classes

The constituent tag libraries of Standard Taglib are as follows:

Funtional Area URI Prefix Example
Core http://java.sun.com/jsp/jstl/core
c
tagname ...>
XML processing http://java.sun.com/jsp/jstl/xml
x
tagname ...>
I18N capable formatting http://java.sun.com/jsp/jstl/fmt
fmt
tagname ...>
Database access (SQL) http://java.sun.com/jsp/jstl/sql
sql
tagname ...>
Functions http://java.sun.com/jsp/jstl/functions
fn
fn:functionName

Jakarta JSTL Library