pb of succession of search

ChemAxon 587f88acea

29-07-2004 14:49:45

hello





we develop a chemoinformatic plateform on a linux environment in JSP.we use a JchemSearch for searching several substructure(s) or exact molecule(s) in severals data bases. So, there is a succession of search. the problem is that we need to make a wait ( a thread.sleep(60000) => 1 minute) between two searches (or more), because without this pause, the second search returns nothing.


We don't know if it's a problem of JChemSeach.


the JChemSearch is in a method which create this object and return the result; the method is in a java class . In a JSP, there is two loops : one for the databases, one for the substructure molecule.


So if you are an idea, thanks to help us





Christophe and fabien





ps : and sorry for the bad english :(

ChemAxon 9c0afc9aaf

29-07-2004 20:01:12

Hi,





Please clarify the following:





- the version of jchem


(see http://www.chemaxon.hu/forum/ftopic127.html if in doubt)





- do you run JChemSearch in the background ? (setWaitingForResult)





- have you checked that the previous search has already finished ?


(isRunning())





After calling JChemSearch.run() please make sure that you leave 1-2 milliseconds, so the running state of the search can actually change to true in the other thread.

ChemAxon 587f88acea

30-07-2004 07:24:12

hi,


So,we are the 2.2.1 version of jchem


we don't use the setWaitingForResult, because, this method made a long loop in our program and maybe a infinity loop(?!).





in the jsp, I want to have the molecules with les differents substructures in the differents databases.So I have a databases loop and an other structure loop included in the first, and this method below is called in this last loop.





public int[] search(boolean bool) throws Exception {


JChemSearch truffier;


int nb_result=0;


int[] index=null;





truffier = new JChemSearch();


truffier.setConnectionHandler(ch);


truffier.setStructureTable("structure");


if(bool){


truffier.setSearchType(JChemSearch.SUBSTRUCTURE);


}else {


truffier.setSearchType(JChemSearch.EXACT);


}


truffier.setQueryStructure(smi);


truffier.run();


while (truffier.isRunning()) {}


nb_result = truffier.getResultCount();


if(nb_result>0) {


index = new int[nb_result];


int [] tmp = truffier.getResults();


for(int i=0;i<nb_result;i++){


index = tmp;


}


}


Thread.sleep(60000); // the bad thing


return(index);


}





I'm going to try with a thread.sleep just after the '.run()'


thx!

ChemAxon 9c0afc9aaf

30-07-2004 14:06:15

Using setWaitingForResult(true) should not cause any problems in general, although for web applications a separate thread is recommended, so the page can be periodically refreshed without server / browser timeout on a longer search.








It's very important to have some Thread.sleep in the waiting thread.


Otherwise the processor will work hard on the empty cycle, and it will barely have time to calculate the search, making it much slower.





So instead of this:





while (truffier.isRunning()) {}





use this:





while (truffier.isRunning()) {


Thread.sleep(200);


}





Of course this sleep is not necessary, if you are only checking the search status when the page is refreshed. (in every one or two seconds)


For an example on that please see our JSP search example in the JChem package: jchem\examples\jsp1_x


The file "searching.jsp" is refreshing the page, while the search runs in the background.





(Live version can be found at: http://www.jchem.com/examples/jsp1_x/index.jsp)





Apart from this missing Thread.sleep() I don't see any reason for errors.