You are currently browsing the daily archive for October 5, 2006.

Expand reach to collaborative processes which are often paper or Excel-based and preceding or parallel to processes covered in back-end systems.

Business need
• Many users work based on paper, Excel, or mail
• Volatile processes which are not tracked (not measurable)
• Processes inside current systems are not flexible enough
• Implement new processes without upgrading the existing ones

Approach
• Build Packaged Composite Applications covering
• Use SOA for integrating with back-ends
• Use modeling to offer the flexibility needed

Summary
1. Composite Applications empower companies to drive innovative business processes leveraging existing IT investments.

2. Composite Application Frameworks (like SAP CAF) provide a methodology and toolset to efficiently develop and manage composite applications—following SOA principles.

3. Metadata-based modelling tools help developers to abstract from technologies, frameworks, and programming languages and at the same time improve flexibility, productivity, and quality.

Ref:
Challenges and Solutions for Developing Composite Applications on the Java EE Platform

Advertisements

First using the magic of an extended stored procedure, we can call our console application from an MS SQL trigger. We create our table in Enterprise Manager and then use the trigger to call our console application. You could also call a COM object for that purpose.

1. Using SQL trigger

On the SQL side, we’ve set-up a trigger within our table of e-mail addresses. Upon updating a record, it will get the ID of the changed record and then call the console application by using xp_cmdshell. The xp_cmdshell is an extended stored procedure.

This is a special DLL written in Microsoft Visual C++ .NET. It is comes standard with MSSQL Server. In SP3 for MSSQL Server you need to give the user calling this stored procedure rights to call console applications.

Ref:
15 Seconds : Queue MSMQ Messages from SQL Server

15 Seconds : Leveraging MSMQ in ASP.NET Applications

2. Accessing COM Objects from Java

In this section we describe how you can create an instance of a COM object, and use it from Java using J-Integra. We also explain how to deal with new references to COM objects that are returned from method calls to COM objects:

Ref:
J-Integra for COM

1. Many threads can be started in an object that implements Runnable. An alternative way to start a thread is for the object to subclass Thread but this will only one thread to be started.

import java.util.*;  

public class ThreadDemo implements Runnable { 
  protected Thread execution;  

  public synchronized void begin() { 
     if(execution == null){ 
         execution = new Thread(this); 
         execution.setPriority(Thread.MIN_PRIORITY); 
         execution.start(); 
     } 
  }  

  public synchronized void end() { 
    if(execution != null){ 
        execution.interrupy(); 
        execution = null; 
     } 
  }  

  public void run() { 
    try { 
       Thread myself = Thread.currentThread(); 
       while(execution == myself){ 
               //body 
       } 
    }finally { 
       synchronized (this){ 
       execution = null; 
    } 
  } 
}

2. A producer-consumer example. Common problem is solved by thread and semaphore.

import java.io.*; 
import java.util.*; 

public class Consumer extends Thread { 
    protected Vector objects; 

    public Consumer () { 
        objects = new Vector(); 
    } 

    public void run () { 
        try { 
             while (true) { 
                  Object object = extract (); 
                  System.out.println (object); 
             } 
        } catch (InterruptedException ignored) { } 
    } 

    protected Object extract () throws InterruptedException { 
         synchronized (objects) { 
              while (objects.isEmpty ()) { 
                  objects.wait (); 
              } 
              Object object = objects.firstElement (); 
              objects.removeElementAt (0); 
              return object; 
         } 
    } 

    public void insert (Object object) { 
         synchronized (objects) { 
              objects.addElement (object); 
              objects.notify (); 
         } 
    } 

    public static void main (String[] args) throws IOException, InterruptedException { 
        Consumer consumer = new Consumer (); 
        consumer.start (); 
        BufferedReader keyboard = new BufferedReader (new FileReader (FileDescriptor.in)); 
        String line; 
        while ((line = keyboard.readLine ()) != null) { 
            consumer.insert (line); 
            Thread.sleep (1000); 
        } 
    } 
}

3. Efficient multithreading. Recycle the threads like threads pool in JDK 5.0.

import java.util.*; 

public class ReThread implements Runnable { 
    protected Runnable target; 

    public ReThread (Runnable target) { 
        this.target = target; 
    } 

    private static int id = 0; 
    private static synchronized int getID () { return id ++; } 

    private static Vector threads = new Vector (); 
    private ReThread reThread; 
    private Thread thread; 

    public synchronized void start () { 
        if ((thread == null) && (reThread == null)) { 
              synchronized (threads) { 
                   if (threads.isEmpty ()) { 
                         thread = new Thread (this, "ReThread-" + getID ()); 
                         thread.start (); 
                   } else { 
                         reThread = (ReThread) threads.lastElement (); 
                         threads.setSize (threads.size () - 1); 
                         reThread.start0 (this); 
                   } 
              } 
        } 
    } 

    protected synchronized void start0 (ReThread reThread) { 
        this.reThread = reThread; 
        target = reThread.target; 
        notify (); 
    } 

    public synchronized void interrupt () { 
        if ((target != null) && ((thread != null) ^ (reThread != null))) { 
             if (thread != null) { 
                   thread.interrupt (); 
             } else { 
                   reThread.interrupt0 (this); 
             } 
        } 
    } 

    protected synchronized void interrupt0 (ReThread reThread) { 
        if ((target != null) && (reThread == this.reThread)) { 
              thread.interrupt (); 
        } 
    } 

    public void run () { 
        while (true) { 
            try { 
                target.run (); 
            } catch (RuntimeException ex) { 
                ex.printStackTrace (); 
            } 
            waitForTarget (); 
        } 
    } 

    protected synchronized void waitForTarget () { 
        target = null; 
        threads.addElement (this); 
        while (target == null) { 
            try { 
               wait (); 
            } catch (InterruptedException ignored) { } 
        } 
    } 
}

Memory Leaks:

Problem #1:

  • Lapse Event Listeners:
  • AWT Swing
  • Event Listener Design

Solution #1:

  • remove listener
  • shorten object life cycle
  • soft/weak references

Problem #2:
Leak Collections:

  • cache
  • session state
  • user interface
  • EJB container

Solution #2:

  • search for common warning signs
  • aggresively pair adds with remove
  • use soft references for cache
  • use finally
  • use collections with weak references

Ref:
Plugging memory leaks with weak references
Plugging memory leaks with soft references