Hi Team, Our web application has a "header.jsp" which has 2 Arraylist on it. Each ArrayList has more than 50 items inside. The code is to identify the mobile device and requested page and transfer the call to mobile page accordingly.
This code works fine once we restart the server and can continue running 2 months without any issue. But day by day it starts showing 500 error with exception in log "ConcurrentModificationException". Below is the code snippet of JSP code. My Question is why this issue is happening around 2 months? If we clear the temp file created by the server in work folder then that will run for some time( 2- 3 days) and then again the same exception starts occurring. I have identified one solution by moving the JAVA code from JSP to JAVA file which worked good while perform testing but client wants to know the root cause of the issue. FYI, earlier we had Vector in place of Arraylist which gave trouble of thread blocking due to synchronization. So, converting from Arraylist to Vector will not be a good idea. Exception: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859) at java.util.ArrayList$Itr.next(ArrayList.java:831) at org.apache.jsp.includes.header_jsp.isHomePage(header_jsp.java:97) Code Snippet: <%! private Set uas = new HashSet(); ArrayList<String> urlnames = new ArrayList<String>(); ArrayList<String> excludePathList = new ArrayList<String>(); private boolean haveToRedirect(HttpServletRequest request, String stopMobiCookie) { boolean doRedirect = false; String userAgent = request.getHeader("User-Agent"); if (! stopMobiCookie.equals("yes") && userAgent != null && userAgent.length()!=0 && (userAgent.indexOf("UsableNet")==-1)) { Iterator iter = uas.iterator(); while (iter.hasNext()) { if (userAgent.indexOf((String)iter.next())!=-1) { doRedirect = true; break; } } } return doRedirect; } private boolean isHomePage(HttpServletRequest request){ Iterator<String> itr = urlnames.iterator(); String path = ""; while (itr.hasNext()) { path = itr.next(); if (request.getRequestURI().toString().equalsIgnoreCase(path)){ return true; } } return false; } private boolean isExcludePath(HttpServletRequest request){ Iterator<String> itr = excludePathList.iterator(); String path = ""; while (itr.hasNext()) { path = itr.next(); if (request.getRequestURI().startsWith(path) && !request.getRequestURI().startsWith("/info/contact.jsp")){ return true; } } return false; } %> <% uas.add("Blazer"); uas.add("Danger hiptop"); uas.add("DoCoMo/"); uas.add("Ericsson"); uas.add("Googlebot-Mobile"); uas.add("MSN Mobile Proxy"); uas.add("Handheld"); uas.add("HTC_HD2_T58585 Opera"); uas.add("iPhone"); uas.add("iPod"); uas.add("Klondike"); uas.add("LG-"); uas.add("LGE-"); ....... Arround 40 items excludePathList.add("/business/my_account"); excludePathList.add("/business/save_energy"); excludePathList.add("/business/services"); excludePathList.add("/business/small_large_business"); excludePathList.add("/info/environment"); excludePathList.add("/info/about"); excludePathList.add("/info/index.jsp"); excludePathList.add("/info/ambassador.jsp"); ........ more than 50 items stopMobiCookie = some cookie code boolean doRedirect = haveToRedirect((HttpServletRequest)request, stopMobiCookie); if(doRedirect){ boolean isHomePage = isHomePage((HttpServletRequest)request); boolean isExcludePath = isExcludePath((HttpServletRequest)request); session.setAttribute("mobile_agent", "yes"); if(!isHomePage && !isExcludePath){ String mobileServer = "mobile.server.com"; try{ mobileServer = mobileServer + request.getRequestURI().toString(); }catch(Exception e){} %> <script type="text/javascript"> window.location ="<%=mobileServer%>"; </script> <% } } %> Thanks & Regards Subhro Paul =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you