Results 1 to 2 of 2
- 01-16-2008, 10:01 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
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;
}
}
- 01-17-2008, 03:01 AM #2
Similar Threads
-
Are Local variables thread safe ?
By samson in forum Threads and SynchronizationReplies: 6Last Post: 12-21-2010, 02:34 PM -
The safe way to stop a thread
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:31 PM -
how to get the data from hashmap into bean in struts framework
By java_arc in forum Advanced JavaReplies: 0Last Post: 04-07-2008, 07:54 PM -
Struts Validator Framework
By Albert in forum Web FrameworksReplies: 2Last Post: 02-15-2008, 11:01 AM -
Local Variables for a static method - thread safe?
By mikeg1z in forum Advanced JavaReplies: 1Last Post: 11-16-2007, 01:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks