Mohan Ramamoorthy

Greenhorn
+ Follow
since Jan 31, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mohan Ramamoorthy

Hi,

We have deployed Richfaces web application in JBOSS-EAP-4.3. Due to the following exception the CPU spikes to 90%.

Thread: http-10.20.81.200-17180-31 : priority:5, demon:true, threadId:337, threadState:RUNNABLE, lockName:null
java.util.HashMap.get(HashMap.java:305)
org.apache.catalina.connector.Request.getAttribute(Request.java:878)
org.apache.catalina.connector.RequestFacade.getAttribute(RequestFacade.java:263)
com.sun.faces.application.WebappLifecycleListener.attributeReplaced(WebappLifecycleListener.java:168)
com.sun.faces.config.ConfigureListener.attributeReplaced(ConfigureListener.java:318)
org.apache.catalina.connector.Request.setAttribute(Request.java:1435)
org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:284)
com.sun.faces.context.RequestMap.put(ExternalContextImpl.java:1087)
org.ajax4jsf.event.AjaxPhaseListener.afterPhase(AjaxPhaseListener.java:81)
com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

After the initial analysis, we have found out that the “attributes” hashmap in org.apache.catalina.connector.Request is causing the issue. Since the hashmap is not thread safe, it ends up in an infinite loop. Session (org.apache.catalina.session.StandardSession) also has the similar implementation of “attributes” but it is made as concurrent hash map to avoid the concurrency issue. Is there any reason why the Request#attributes hashmap is not made as concurrent hash map ? Also is there any workaround available to fix this issue ?

Can anyone help us in resolving this issue.


Regards,
Mohan R
12 years ago
Hi Cameron,
I had the same problem earlier and I tried a lot to find out the solution. All went into vein. I did some workaround for this problem. I am not sure that this is the proper solution. But I am sure that it will be helpful to you.

It has few steps to follow
1. Identify each page by some constant value.(ref steps 2.b and 2.d)
2. Implement a class with PhaseListener.
a) depends on the requirement you can use afterPhase/beforePhase method.
b) retrive the page-reference constant from session.
c) use switch case,to find out the appropriate backbean and method
For eg. (mybackbean is your BackBean and init is your your method)

FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
MethodBinding methodBinding = application.createMethodBinding(
"#{mybackbean.init}", null);
if (methodBinding != null) {
try {
methodBinding.invoke(context, null);
} catch (Throwable e) {
}

This code calls the corrosponding method.
d) save the new page-reference in the session

3. Configure the phaselistener in faces-config.xml


The init method shown in the code piece executes the business logic for you..

let me know, if you have any problem with this solution.
16 years ago
JSF
Hi I am new to JSP. I need to send a mail from my JSP pages.
can i use the Yahoo's SMTP and POP3 ( smtp.mail.yahoo.com )
and pop.mail.yahoo.com )for this purpose. If it is so how can i use it. Can u please post some code examples.

Thanx in Advance
Mogli
17 years ago
JSF
Hi Friends,
Can any one help us really confuse
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }
Which two are valid in a class that extends class A? (Choose two)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0: }
E. static protected int method1(int a, int b) { return 0; }


As per my point of view the answer is only (A)

B and C are assigning weaker privelleges to the protected method.
D is having different return type. The compiler won't allow this.
E is having static refrence.( it overloads static base class methods )
Welcome shannon

Regards
Mohan
18 years ago
Hi Shannon,
Hope this code will solve ur requirement.Here the createDefaultModel() method is overridden with our requirement.
So now the keylistener is not necessary for this implementation even focus listener also.
We can use normal requestFocus() method to change the focus.

During the TextField initialization add these code


JTextField myTextField = new JTextField();
myTextField.setDocument(createDefaultModel());
..............

and add these two methods..

protected javax.swing.text.Document createDefaultModel()
{
return new javax.swing.text.PlainDocument() {
public void insertString(int offset, String value,
javax.swing.text.AttributeSet as)
{
if (isValid(offset, value, as))
{
try
{
super.insertString(offset, value, as);
}
catch (javax.swing.text.BadLocationException e)
{
System.out.println("Exception in insertString() of FolderField : " + e);
}
}
}
};
}


private boolean isValid(int offset, String value, javax.swing.text.AttributeSet as)
{
//check the valid characters
if (offset < 3)
{
for (int i = 0; i < value.length(); i++)
{
if (i > 3 ||Character.isDigit(value.charAt(i)) == false)
{
java.awt.Toolkit.getDefaultToolkit().beep();
return false;
}
}
return true;
}
return false;
}
18 years ago
Hai
Ur code is interpreted in this way

Ur code

int i =1;
do while(i>1)
System.out.println("is it possible");
while(i>1);

interpreted like
do{ while (i>1)
System.out.println("is it possible");
}while(i>1);

similiarly u can code like this also
A)
int i =1;
do if(i>1)
System.out.println("is it possible");
while(i>1);
B)
int i =1;
do for(;i<1
System.out.println("is it possible");
while(i>1);

Regards
Mohan
I hope java compiler is doing left precedence rule for the operations
case 1 : a+b+c ===> normal arithmetic operation results 15
(10+5+0=15)
case 2 : ""+a+b+c ===> takes the string operation
"" +10 = "10"
"10" + 5 = "105"
"105"+ 0 = "1050"
case 3 : a+b+c+"" ===> same as first one and then added with
empty string (15 + "" = "15")

Hope this will be useful