Thread Pool in java

Threads are a very important Part of Java, but creating large numbers of threads can degrade the performance of application.By thread pools, which allow you to maintain fixed number of threads running assigned tasks to each of the threads.
Suppose A thing may have to visit tens of thousands of pages, and you will not create tens of thousands of thread because it is an additional problem. For overcome this problem we need a thread pool. Thread pool give some fixed number of thread and these thread will do task. Once a thread finish one task, then it is assigned to new task. We will not create a new thread always. This is way thread pool will work. Developer has to implement this feature.
In Java:
• A thread pool implementation is provided in the form of the ThreadPoolExecutor class, introduced in Java 1.5;
• you can put in different implementations of BlockingQueue to specify different queue behavior such as queue bounds or priority ordering

Implementation of Thread pool

This can be done by like this

 
   public class ThreadPool extends java.lang.Object implements ThreadPoolInt 

This class is generic implementation of thread pool which have following input
1) Size of the pool to be constructed
2) Name of the class which implements Runnable (which has a visible default constructor)

It constructs a thread pool with active threads that are waiting for activation. Once the threads have finished their task they will come back and wait for assigning a new task.

Benefits of Thread Pooling
• It saves the machine work of creating a new thread.
• Single thread can recycle again and again.
• The size of thread pool is given in starting .We can expand on the designs presented in this chapter to include a method to support growing the size of the pool at runtime if you need this kind of dynamic tuning.
• Response time can be quick.

Risks of using thread pools
The disadvantage of thread pool is that. Suppose if an task is rejected because the thread pool is empty. There will be high rejection rate.Or if task on wait state then waiting time would be too long. Sometime there is problem of deadlock also.

References
http://www.japisoft.com/jservices/javadoc/jason/service/pool/ThreadPool.html
http://java.sun.com/developer/Books/javaprogramming/threads/chap13.pdf

Conditionally colouring of row cell in adf

Some time, in our application we need to display some table cells highlighted with some colours.for different condition we need Different colour of row or some particular cell. This can be possible by using expression language(EL) .We can write an ternary operation in expression language(EL).For example if we are displaying data in tabular structure .And we want to highlight the Employee id which have salary eq to ‘50000’.For this , we can write below expression in INLINE PROPERTY OF EMPLOYEE ID.
After writing this EL in INLINE Property we can give conditionally coloring in table cells.

 
background-color:#{(row.salary eq "50000"?'Aqua':'')}

This El mean if salary of corresponding row is equal to 50000 then table cell color will be aqua. Similarly we can use GT and LT for greater than or less than respectively.

Executing the view object query in Oracle ADF

In oracle ADF, for executing the view object query we need to write code for that.This code is needed for refreshing the table content after executing some DML operation.For that we need to execute the query of view object.For that write an in application module Impl.java file.For an example look the below code-

 


    public void refreshVinayView()
    {
VinayViewObject  vinay= get VinayViewObject 1();
        vinay.executeQuery();
    }

After writing in AppmoduleImpl.java file.save your application and double click on app module.Go to client interface and shuttle right to this method “refreshVinayView” .
After that From where you what to execute the view object query.For example- we are deleting some row from table and want to reexecute the query again then we can write the code in specific java file of some .jspx file.Sample code is as below.

   FacesContext fctx = FacesContext.getCurrentInstance();
        ValueBinding vb = 
            fctx.getApplication().createValueBinding("#{bindings}");
        DCBindingContainer dcb = (DCBindingContainer)vb.getValue(fctx);
        OperationBinding operation = 
            (OperationBinding)dcb.get("refreshVinayView ");
        operation1.execute();

One more thing needed.Go to page definition of that specific .jspx file. And in Binding tab in structure window.Right click the binding tab and go to method action.An “Action binding editor” window will open.Select your java method in SELECT AN ACTION drop down and press ok.

This is all you need to execute the view object the query.