javacommons/utils/javasrc/com/nokia/mj/impl/rt/JvmPort.java
changeset 80 d6dafc5d983f
parent 26 dc7c549001d5
--- a/javacommons/utils/javasrc/com/nokia/mj/impl/rt/JvmPort.java	Mon Oct 04 11:29:25 2010 +0300
+++ b/javacommons/utils/javasrc/com/nokia/mj/impl/rt/JvmPort.java	Fri Oct 15 12:29:39 2010 +0300
@@ -39,16 +39,18 @@
     private static final String PORTCLASS_PACKAGE = "com.nokia.mj.impl.rt.";
 
     /**
-     * When the class is loaded it will try to create the VM porting class
-     * defined in the system property PORTCLASS_PROPERTY_NAME
+     * When the getInstace() is first called it will be tried to create the
+     * VM porting class defined in the system property PORTCLASS_PROPERTY_NAME.
+     * The package visiblity is set to protected for unit testing purposes.
      */
-    private static JvmPort sInstance = null;
+    protected static JvmPort sInstance = null;
 
     /**
      * A reference to object containing properties. In CLDC it is Hashtable,
      * otherwise it is Properties.
+     * The package visiblity is set to protected for unit testing purposes.
      */
-    private static DynamicProperty mPropertiesContainer;
+    protected static DynamicProperty mPropertiesContainer;
 
     protected JvmPort()
     {
@@ -57,8 +59,12 @@
     /**
      * Static initializer
      */
-    static
+    private static synchronized void loadImpl()
     {
+		if (sInstance != null)
+		{
+			return;
+		}
         String vmPortClass = System.getProperty(PORTCLASS_PROPERTY_NAME);
         if (vmPortClass == null)
         {
@@ -74,8 +80,7 @@
         }
         catch (Exception e)
         {
-            String errTxt = "Not able to instantiate class " +
-                            vmPortClass + ".";
+            String errTxt = "Not able to instantiate class " + vmPortClass;
             Logger.ELOG(Logger.EUtils, errTxt, e);
             throw new RuntimeException(errTxt);
         }
@@ -88,6 +93,10 @@
      */
     public static JvmPort getInstance()
     {
+        if (sInstance == null)
+        {
+            loadImpl();
+        }
         return sInstance;
     }
 
@@ -125,7 +134,7 @@
     public abstract void setThreadAsDaemon(Thread Thread,
                                            boolean daemon)
     throws IllegalThreadStateException,
-                SecurityException;
+        SecurityException;
 
 
     /**