Wednesday, November 28, 2012

Volatile Vs Non-Volatile Variables in Java ???

If you are working with the multithreaded programming, the volatile keyword will be more useful. When multiple threads using the same variable, each thread will have its own copy of the local cache for that variable. So, when it’s updating the value, it is actually updated in the local cache not in the main variable memory. The other thread which is using the same variable doesn’t know anything about the values changed by the another thread. To avoid this problem, if you declare a variable as volatile, then it will not be stored in the local cache. Whenever thread are updating the values, it is updated to the main memory. So, other threads can access the updated value.

Declaration :
                  private volatile int x;

Thanks,

Interceptors Vs Filters???

1) The most significant difference is that "interceptors" are a part of the Struts 2 framework, and are only part of requests handling that is done by the Struts 2 framework.
 "Filters" on the other hand are a part of the Servlet Specification in other words, they are part of the Servlet API. If you are using Struts 2, you should user interceptors for wrapping functionality around your Struts 2 actions. If you are trying to wrap functionality around requests coming to your web application, but not being handled by Struts 2, then a filter might be more appropriate.

2) The Interceptor stack fires on requests in a configured package while filters only apply to their mapped URLs.

3)Interceptors can be configured to execute or not depending on specific target action methods via excludeMethods and includeMethods while Filters lack this feature.

Filters are an implementation of the Intercepting Filter pattern while Interceptors are of the Interceptor pattern.

Thanks,

Integration of EXTJS with Struts 2

We need to just keep Extjs files in the page and the name of the components should be the same as the name of the attributes in Action so that we can refer those for the sake of validation.
In Struts 2.0 and above,We just need to make a single xml instead of two in Struts 1.x,with the name "ActionClassName-validation.xml" and this must be kept in the class path of the application.
To display error messages in view page,we can use <s:fielderror/>.

Thanks,