Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-16-2008, 11:01 PM
Member
 
Join Date: Jan 2008
Posts: 1
JavaAl2 is on a distinguished road
Struts framework. Is this thread safe?
Hi,
In the FOOAction.execute method, there are two local variables (ExcelHelperBean and rData ) used for datacollection. The rData is a reference to the FOODAO class. In the FOODAO.getReportData method, it initializes a Collection (via ArrayList), executes a select statement, and returns the Collection of FooBean(s). Because both of the methods have local variables instead of Class level variables, they are thread safe. Correct?
I should not have to synchronize, correct?


public class FOOAction extends Action implements ReportDefinitions
{

static Logger log = Logger.getLogger(FOOAction.class.getName());

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws Exception
{
ActionMessages errMsgs = new ActionMessages();
HttpSession session = request.getSession();
Fields fields = new Fields();
boolean error = false;
IncidentTimeDateForm fooForm = (FOOForm) form;
String strName = fooForm.getname();

try
{
//Helper Bean per Actionclass
ExcelHelperBean excelHelperBean = new ExcelHelperBean();
//Init DAO
ReportQuery rData = new FOODAO();
Map htUser = new HashMap();

htUser.put(ReportDefinitions.NAME,strName);
//Place results into a Collection for iterating through on jsp
//
excelHelperBean.setColExcelData(rData.getReportDat a(htUser));

request.setAttribute(ReportDefinitions.EXCELHELPER CLASS,excelHelperBean);


}
catch (Exception e)
{
e.printStackTrace();
return mapping.findForward(ReportDefinitions.FAIL);
}
return mapping.findForward(ReportDefinitions.SUCCESS);

}



}
public class FOODAO extends BaseDAO
{
private final static String FASQL = "select distinct per.LASTNAME,i.USERID,pro.PROVIDER,"+
" it.DESCRIPTION,TO_CHAR(i.INCIDENTDATETIME,'MM/DD/YYYY') as incidentdate,"+
" TO_CHAR(i.INCIDENTDATETIME,'DAY') incidentDay, "+
" TO_CHAR(i.INCIDENTDATETIME,'HH24:MI') incidentTime,location.description locDescription "+
" from incident i,incident_incidenttype iit, incident_type it,provider pro,source, incident_participant ip,"+
" participant part, person per,location where i.name='";

public Collection getReportData(Map mValues ) throws Exception
{
Statement stmt = null;
ResultSet rs = null;
Collection calFirstAid = new ArrayList();

String sName =mValues.get(ReportDefinitions.NAME).toString();


StringBuffer sbSQL = new StringBuffer(FASQL);
try
{

sbSQL.append(sName).append("'");
//GetConnection from BaseClass
openConnection();
stmt = conn.createStatement();

rs = stmt.executeQuery(sbSQL.toString());
FooBean faBean = null;
System.out.println("SQL "+sbSQL);
while (rs.next())
{
faBean = new FooBean();
faBean.setLastName(rs.getString("LASTNAME"));
faBean.setIncidentTrackingno(rs.getString("USERID" ));
faBean.setProviderName(rs.getString("PROVIDER"));
faBean.setTypeDescription(rs.getString("DESCRIPTIO N"));
faBean.setIncidentDate(rs.getString("INCIDENTDATE" ));
faBean.setIncidentDay(rs.getString("INCIDENTDAY")) ;
faBean.setIncidentTime(rs.getString("INCIDENTTIME" ));
faBean.setLocDescription(rs.getString("locDescript ion"));

calFirstAid.add(faBean);
}

}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
closeStatement(stmt);
closeConnection();
}

return calFirstAid;

}

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-17-2008, 04:01 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Welcome to the forum JavaAl2,

What you said in first paragraph is right, as long as you don't have shared resources (including static/class level variables) you don't need to worry about thread safety.
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The safe way to stop a thread Java Tip java.lang 0 04-09-2008 07:31 PM
how to get the data from hashmap into bean in struts framework java_arc Advanced Java 0 04-07-2008 08:54 PM
Struts Validator Framework Albert Web Frameworks 2 02-15-2008 12:01 PM
Local Variables for a static method - thread safe? mikeg1z Advanced Java 1 11-16-2007 02:06 AM
Are Local variables thread safe ? samson Threads and Synchronization 3 08-09-2007 07:59 PM


All times are GMT +3. The time now is 08:33 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org