The descriptor code is not thread safe. I think there was some work
sometime back on going through and making classes threadsafe, but I
don't think it to the descriptors

On Fri, Mar 23, 2012 at 11:20 AM, lochana menikarachchi
<[email protected]> wrote:
> Following code run into concurrent modification exception when ran in more
> than 1 thread. Any ideas??
>
>         ExecutorService eservice = Executors.newFixedThreadPool(threads);
>         CompletionService <List<String>> cservice = new
> ExecutorCompletionService <List<String>> (eservice);
>         int k=0;
>         for (IAtomContainer mol : mols3D)
>         {
>             DescCalculator dc = new DescCalculator(mol);
>             cservice.submit(dc);
>             k=k+1;
>
>         }
>
> ---------------------------------------------------------------------------------
>
> public class DescCalculator implements Callable<List<String>>{
>
>     private IAtomContainer mol;
>
>     DescCalculator(IAtomContainer mol_)
>     {
>         this.mol = mol_;
>     }
>
>     @Override
>     public List<String> call() {
>         List<String> dataItems = new ArrayList<String>();
>         try
>         {
>         DescriptorEngine engine = new
> DescriptorEngine(DescriptorEngine.MOLECULAR);
>         List<String> classNames = engine.getDescriptorClassNames();
>         List<String> removeList = new ArrayList();
>
> removeList.add("org.openscience.cdk.qsar.descriptors.molecular.IPMolecularLearningDescriptor");
>         classNames.removeAll(removeList);
>         List<IDescriptor> instances =
> engine.instantiateDescriptors(classNames);
>         engine.setDescriptorInstances(instances);
>         ArrayList<IMolecularDescriptor> descriptors = new ArrayList();
>         for (Object object : instances)
>         {
>         IMolecularDescriptor descriptor = (IMolecularDescriptor) object;
>         descriptors.add(descriptor);
>         }
>             String title = (String) mol.getProperty("PUBCHEM_COMPOUND_CID");
>             dataItems.add(title);
>             int ndesc = 0;
>             for (IMolecularDescriptor descriptor : descriptors) {
>                 DescriptorValue value = descriptor.calculate(mol);
>                 if (value.getException() != null) {
>                     for (int i = 0; i < value.getNames().length; i++) {
>                         dataItems.add("NA");
>                     }
>                     continue;
>                 }
>
>                 IDescriptorResult result = value.getValue();
>                 if (result instanceof DoubleResult) {
>                     dataItems.add(String.valueOf(((DoubleResult)
> result).doubleValue()));
>                 } else if (result instanceof IntegerResult) {
>                     dataItems.add(String.valueOf(((IntegerResult)
> result).intValue()));
>                 } else if (result instanceof DoubleArrayResult) {
>                     for (int i = 0; i < ((DoubleArrayResult)
> result).length(); i++) {
>                         dataItems.add(String.valueOf(((DoubleArrayResult)
> result).get(i)));
>                     }
>                 } else if (result instanceof IntegerArrayResult) {
>                     for (int i = 0; i < ((IntegerArrayResult)
> result).length(); i++) {
>                         dataItems.add(String.valueOf(((IntegerArrayResult)
> result).get(i)));
>                     }
>                 }
>
>                 ndesc++;
>             }
>
>         }
>         catch(Exception e)
>         {
>             e.printStackTrace();
>         }
>         return dataItems;
>     }
>
> }
>
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user
>



-- 
Rajarshi Guha | http://blog.rguha.net
NIH Center for Advancing Translational Science

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to