Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

ArrayList

I have an interface on the bean which is hit by multiple Users

can the methods interface to this interface use ArrayList without synchronisation?

public CsrData getTelcoCsrForQual(String tn, String qualTrackNum, String state, String txnum, String provOption, boolean dbCheck) throws ServicesApplicationException
{
    List l1 = new ArrayList();
 }

will it impact multi threading?
0
skn73
Asked:
skn73
  • 3
  • 2
1 Solution
 
petmagdyCommented:
u only need to synchronize Objects has life time that span the method life time, to explain more if ur class looks like this:

Class MyClass
{
 List l1 = new ArrayList();

 public CsrData getTelcoCsrForQual(String tn, String qualTrackNum, String state, String txnum, String provOption, boolean dbCheck) throws ServicesApplicationException
{
    l1 = new ArrayList();
 }

}

and thsi class instance is shared between  different threads then u need to manage sync.

but if MyClass is like this:

Class MyClass
{

 public CsrData getTelcoCsrForQual(String tn, String qualTrackNum, String state, String txnum, String provOption, boolean dbCheck) throws ServicesApplicationException
{
    List l1 = new ArrayList();
 }

}

no warry because l1 is local in the method
0
 
skn73Author Commented:
Class MyClass
{

 public CsrData getTelcoCsrForQual(String tn, String qualTrackNum, String state, String txnum, String provOption, boolean dbCheck) throws ServicesApplicationException
{
    List l1 = new ArrayList();
   editRsp(l1);
 }

public boolean editRsp(List l1)
{
   //some processing....
}

public CsrData getTelcoCsrForDSL(String tn, String qualTrackNum, String state, String txnum, String provOption, boolean dbCheck) throws ServicesApplicationException
{
     List l1 = new ArrayList()
     editRsp(l1);
}

}
This is how it looks....
0
 
skn73Author Commented:
so I am thinking it need not be synchronized
0
 
petmagdyCommented:
yes no need to be synchronized, syncronization is for common instances between different threads
0
 
skn73Author Commented:
Thanks..
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now