• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and Synchronization  RSS feed

 
Gopinath Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

Any one can pls tell me
1, How one thread will communicate with another thread ?

2, How to write a thread safe application?

3, What is the use of synchronized Block?

I am developing a application i want to make it thread safe. I am doing my buisness logic in Servlets. This is sample code.

try{
synchronized(this){
pstmt=con.prepareStatement(" Some Query here................");
pstmt.setString(1,x);
pstmt.setString(2,x);
pstmt.setString(3,x);
pstmt.setString(4,x);
rs=pstmt.executeQuery();
RowSetDynaClass rsdc=new RowSetDynaClass(rs);
List list=rsdc.getRows();
if(list != null && list.size() > 0){
isDataFound=true;
sBean.setListData("List",list);
}// End if IF
if(pstmt != null)pstmt.close();
if(rs!=null)rs.close();
} // End of Synchronized
}// End of try
catch(SQLException sqle){
logger.error(".....",sqle);
isDataFound=false;
}

In the above code i have done my buisness login with in synchronized block. Is it correct. And is it safe. Whether any thing newly has to be included in this code to make thread safe .

pls suggest me with codings

regards
Gopinath
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!