Tuesday, December 9, 2008

Logging guidelines

INFO Level

  • The start and end of the method
  • The start and end of any major loops
  • The start of any major case/switch statements

DEBUG Level

  • Any parameters passed into the method
  • Any row counts from result sets I retrieve
  • Any datarows that may contain suspicious data when being passed down to the method
  • Any "generated" file paths, connection strings, or other values that could get mungled up when being "pieced together" by the environment.

ERROR Level

  • Handled exceptions
  • Invalid login attempts (if security is an issue)
  • Bad data that I have intercepted forreporting

FATAL Level

  • Unhandled exceptions.

Wednesday, November 19, 2008

PersistentObject hangs when committing

Device: RIM BlackBerry 8830
Software Version: 4.2.2.x

Problem: storing a Double/Float object would hang when committing
i.e.
set(123456789L, new Double(2.0));
set(123456789L, new Float(2.0));

even a Hashtable containing Double/Float would hang also
i.e.
Hashtable ht = new Hashtable();
ht.add("key",new Double(2.0));
set(123456789L, ht);

here is the code snippet:

public void set(long key, Object value) {
PersistentObject store = PersistentStore.getPersistentObject(key);
store.setContents(value);
System.out.println("Before commit");
store.commit();
System.out.println("After commit);
}

Solution: store something else

i.e.
set(123456789L, Double.toString(2.0));
set(123456789L, Float.toString(2.0));
set(123456789L, new Integer(2));
set(123456789L, Boolean.TRUE);
set(123456789L, new Long(2));
set(123456789L, new Short((short)2));

Monday, November 17, 2008

Thread pool for J2ME (BlackBerry)

previously I thought there is no Thread pool implemented within the J2ME library,
actually there is(for RIM's implementation)...........but there is no public interface to access it


guid:0x1234567890123456 time: Mon Nov 17 15:47:31 2008 severity:4 type:2 app:foobar data:CONNECT:Receiver caught:
net.rim.device.cldc.io.ippp.SocketBaseIOException: java.io.IOException: could not connect to foobar.com:1234
at net.rim.utility.transport.tcp.nio.TCPChannel.connect(TCPChannel.java:168)
at net.rim.protocol.iplayer.connection.handler.device.defaulthandlernio.Core.startChannel(Core.java:123)
at net.rim.protocol.iplayer.connection.handler.device.defaulthandlernio.Core.start(Core.java:117)
at net.rim.protocol.iplayer.connection.DeviceInitiatedConnection.connect(DeviceInitiatedConnection.java:395)
at net.rim.protocol.iplayer.connection.DeviceInitiatedConnection.run(DeviceInitiatedConnection.java:485)
at net.rim.utility.threading.JobPoolManager$JobProxy.run(JobPoolManager.java:416)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)

Sunday, November 16, 2008

TooManyThreadsError on J2ME (BlackBerry)

Problem: J2ME(RIM's implementation) limits # of threads creation
How many threads do work simultaneousness at most ?

Solution: Thread pool
--->J2ME doesn't have the luxury of Java 5 concurrent package,

--->Doug Lea's Java 1.4 concurrent package involves too much modification to run on J2ME
http://g.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html

--->Came across O'Reilly's Java Thraeds 3rd edition
http://safari.oreilly.com/0596007825
It includes a simple version of Thread Pool for pre java 5 era.
http://java.codefetch.com/example/qm/javathreads/examples/appa/BusyFlag.java
http://java.codefetch.com/example/qm/javathreads/examples/appa/CondVar.java
http://java.codefetch.com/example/qm/javathreads/examples/appa/DaemonLock.java
http://java.codefetch.com/example/qm/javathreads/examples/appa/JobScheduler.java
http://java.codefetch.com/example/qm/javathreads/examples/appa/ThreadPool.java

Even though this is not a plug-n-play solution for J2ME, but the modification takes only couple minutes.