Thursday, February 23, 2012

Java: Collections


So, this is first Java article, I will start explaining two very important classes related of Java Collections Framework
1)Class java.util.ArrayList and java.util.LinkedList from Java Collections Framework.
These collection Java classes are very important from data perspective.
Important points related of ArrayList|Java Collections:
0-an expandable array. This is the most used and easiest member of the collections framework.
1-If you want to use a thread-safe Collection don’t use ArrayList. Use Vector class as thread-safe.
2-When removing elements, using ArrayList is slow. This is because all remaining elements in the underlying array of Object instances must be shifted
down for each remove operation.So when you need to insert huge amount of objects & || randomly delete them one by one, better to use LinkedList.
3-ArrayList is pretty fast doing random lookup using ‘get’ and LinkedList is slow. So ArrayList works better when you are doing random access on the list and LinkedList works better if you are doing a lot of editing in the middle of the list.
ArrayList Source code example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package arraylistexample;
import java.util.ArrayList;
import java.util.List;
  
/*
 * Class created by Thiago Leoncio -->16 Feb 2012
 */
public class ArrayListExample {
   /**
     * Main method.
     * @param args
     * @goal Shows how it works Java Collections Framework.
     */
    public static void main(String[] args) {
        ArrayList<String> names = new ArrayList<String>();
  
        // Adding values to the ArrayList called names.
        names.add("Thiago");
        names.add("Leoncio");
        names.add("Melaine");
  
        // Retrieving value at position 0.
        System.out.println(names.get(0));
  
        System.out.println("\nIteration ==>1: ");
        // Indexed for loop iteration
        for (int i = 0; i < names.size(); i++) {
            System.out.println(names.get(i));
        }
  
        // Removing items (careful!)
        names.remove(names.size() - 1);
  
        // This will remove the first item and copy the next item and include
        // into the subsequent position. ==> VERY SLOW.
        names.remove(0);
  
        System.out.println("\nIteration ==>2: ");
        for (String value : names) {
            System.out.println(value);
        }
  
        // List interface ...
        List<String> values = new ArrayList<String>();
    }
}
LinkedList source code example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.LinkedList;
  
public class LinkedListExample {
/*
 * Class created by Thiago Leoncio -->16 Feb 2012
 */
  
  public static void main(String[] args) {
    
    //create LinkedList object
    LinkedList ThiagoLinkedList = new LinkedList();
    
    //add elements to LinkedList
    ThiagoLinkedList.add("T");
    ThiagoLinkedList.add("h");
    ThiagoLinkedList.add("i");
    ThiagoLinkedList.add("a");
    ThiagoLinkedList.add("g");
    ThiagoLinkedList.add("o");
  
    /*
     * Also primitive values can not be added into LinkedList.
     * They must be converted to their corresponding wrapper class.
     */ 
    
    System.out.println("This collection contains : " + ThiagoLinkedList);
    
  }
}
2) Class java.util.HashMap:
Maps are data collections that function like lookup tables. A Hashmap is a Map data structure.
So with these 2 phrases you can merge and have these features:
1-Store objects via “keys”. Keys are particular index. This index is called a hash and it is generated using a hash function.
2-You can quickly delete those easily.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package hashmapexample;
import java.util.HashMap;
import java.util.Map;
/*
 * Class created by Thiago Leoncio -->16 Feb 2012
 */
public class HasMapExample {
    /**
      * Main method.
      * @param args
      * @goal Shows how it works HashMap(Java Collections).
      */
    public static void main(String[] args) {
  
        HashMap<Integer, String> map = new HashMap<Integer, String>();
          
        map.put(12, "Thiago Leoncio");
        map.put(15, "Manager");
        map.put(13, "Director");
        map.put(11, "VP");
        map.put(9, "CIO");
           
        String textvalue = map.get(12);  
        System.out.println(textvalue); 
        // this second put will overwrite the first one.
        map.put(9, "CEO");
         
        //Using Map Interface
        for(Map.Entry<Integer, String> entry: map.entrySet()) {
            int key = entry.getKey();
            String value = entry.getValue();
            //Print HashMap Key +: + HashMap value
            System.out.println(key + ": " + value);
        }     
    }
}
I hope this helps,
Thiago Leoncio.

Monday, February 6, 2012

OIM10G:Things to try when Scheduled Tasks are not working


Hi,
I want to discuss a little bit about these common schedule tasks errors and my findings:
20-Dec-2010-08:29:49,874 DEBUG [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ XELLERATE.SCHEDULER – Class/Method: QuartzSchedulerImpl/scheduleJob entered.
20-Dec-2010-08:29:49,874 DEBUG [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ XELLERATE.SCHEDULER – Class/Method: QuartzSchedulerImpl/getQuartzJobDetail entered.
20-Dec-2010-08:29:49,875 DEBUG [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ XELLERATE.SCHEDULER – Creating Quartz Job with job name Manage Reconciliation Events
20-Dec-2010-08:29:49,875 DEBUG [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ XELLERATE.SCHEDULER – Class/Method: QuartzSchedulerImpl/getJobClass entered.
20-Dec-2010-08:29:49,918 FATAL [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ SCHEDULER.WEBSTARTUP – Unable to start scheduler : SchedulerBaseTask
20-Dec-2010-08:29:49,920 DEBUG [ACTIVE] ExecuteThread: ’0′ for queue: ‘weblogic.kernel.Default (self-tuning)’ SCHEDULER.WEBSTARTUP – Class/Method: SchedulerInitServlet/startScheduler left…..
at com.thortech.xl.scheduler.core.quartz.QuartzSchedulerImpl.getJobClass(Unknown Source)
at com.thortech.xl.scheduler.core.quartz.QuartzSchedulerImpl.getQuartzJobDetail(Unknown Source)
at com.thortech.xl.scheduler.core.quartz.QuartzSchedulerImpl.scheduleJob(Unknown Source)
at com.thortech.xl.scheduler.deployment.webapp.SchedulerInitServlet.initializeScheduler(Unknown Source)
at com.thortech.xl.scheduler.deployment.webapp.SchedulerInitServlet.startScheduler(Unknown Source)
at com.thortech.xl.scheduler.deployment.webapp.SchedulerInitServlet.init(Unknown Source)
at $Proxy105.updateUser(Unknown Source)
at com.thortech.xl.schedule.tasks.tcTskUsrDisable.execute(Unknown Source)
at com.thortech.xl.scheduler.tasks.SchedulerBaseTask.run(Unknown Source)
at com.thortech.xl.scheduler.core.quartz.QuartzWrapper$TaskExecutionAction.run(Unknown Source)
….
The explanation is as follows:
OIM9.x uses two different sets of tables to store data about scheduled tasks:
1) OIM tables – TSK/TSA/TSH
2) Quartz tables – QRTZ_* tables
From my understanding this happens because OIM uses an open source library, Quartz, to do task scheduling. So the QRTZ_* tables are used by the Quartz component, and OIM also has its own tables.
The tables used by the OIM UI are the TSK/TSA/TSH tables. The tables used by the actual scheduler engine are the QRTZ_* tables.
The OIM code is supposed to to keep these two in synch. But sometimes things go wrong and they become out of synch. When they are out of synch, the code gets confused, and various errors result. If we remove the contents of the QRTZ tables, OIM will repopulate them correctly based on the data in the TSK/TSA/TSH tables, thus bringing them back in synch.
As to how they get out of synch, I can’t explain that. It is something we see every now and again, but have not seemed to have gotten to the bottom of why exactly. One possible explanation, is if they have any kind of DB or networking error while OIM is trying to update the tables, that could cause them to get out of synch. If this is just a one off occurrence.
To resolve this issue:
Just stop all tasks, remove all contents of these QRTZ_* tables and restart OIM server.
Reference and base of my researches:
Thiago L Guimaraes