Skip to content

Commit 661c691

Browse files
committed
Fix slow RNG by using commons-math RandomUtils instead of commons-lang3
This also removes a deprecated API usage from commons-lang3. The other problematic class that has a slow RNG is RandomStringUtils.
1 parent 7934c9a commit 661c691

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

gemma-cli/src/main/java/ubic/gemma/core/apps/BibRefUpdaterCli.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.commons.cli.CommandLine;
2323
import org.apache.commons.cli.Option;
2424
import org.apache.commons.cli.Options;
25-
import org.apache.commons.lang3.RandomUtils;
25+
import org.apache.commons.lang.math.RandomUtils;
2626
import ubic.gemma.core.util.AbstractAuthenticatedCLI;
2727
import ubic.gemma.model.common.description.BibliographicReference;
2828
import ubic.gemma.persistence.service.common.description.BibliographicReferenceService;
@@ -104,7 +104,7 @@ protected void doWork() throws Exception {
104104
} catch ( Exception e ) {
105105
log.info( "Failed to update: " + bibref + " (" + e.getMessage() + ")" );
106106
}
107-
Thread.sleep( RandomUtils.nextInt( 0, 1000 ) );
107+
Thread.sleep( RandomUtils.nextInt( 1000 ) );
108108
}
109109
}
110110

gemma-core/src/main/java/ubic/gemma/core/ontology/OntologyServiceImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package ubic.gemma.core.ontology;
2020

2121
import io.micrometer.core.annotation.Timed;
22-
import org.apache.commons.lang3.RandomUtils;
22+
import org.apache.commons.lang.math.RandomUtils;
2323
import org.apache.commons.lang3.StringUtils;
2424
import org.apache.commons.lang3.exception.ExceptionUtils;
2525
import org.apache.commons.lang3.time.StopWatch;
@@ -43,7 +43,6 @@
4343
import ubic.basecode.ontology.providers.ObiService;
4444
import ubic.basecode.ontology.search.OntologySearchException;
4545
import ubic.basecode.ontology.search.OntologySearchResult;
46-
import ubic.gemma.persistence.service.genome.gene.GeneService;
4746
import ubic.gemma.core.ontology.providers.GeneOntologyService;
4847
import ubic.gemma.core.ontology.providers.OntologyServiceFactory;
4948
import ubic.gemma.core.search.*;
@@ -56,6 +55,7 @@
5655
import ubic.gemma.model.genome.Taxon;
5756
import ubic.gemma.model.genome.gene.GeneValueObject;
5857
import ubic.gemma.persistence.service.common.description.CharacteristicService;
58+
import ubic.gemma.persistence.service.genome.gene.GeneService;
5959

6060
import javax.annotation.Nullable;
6161
import java.io.BufferedReader;
@@ -979,7 +979,7 @@ private <T> T pollCompletionService( ExecutorCompletionService<T> completionServ
979979
double recheckMs = Math.min( checkFrequencyMillis, timeoutMs );
980980
// a fuzz factor to prevent concurrent tasks from all timing out at the same time
981981
// up to 10% of the initial timeout
982-
double fuzzyMs = RandomUtils.nextDouble( 0.0, checkFrequencyMillis / 10.0 );
982+
double fuzzyMs = RandomUtils.nextDouble() * checkFrequencyMillis / 10.0;
983983
while ( ( future = completionService.poll( ( long ) recheckMs, TimeUnit.MILLISECONDS ) ) == null ) {
984984
long remainingTimeMs = Math.max( timeoutMs - timer.getTime(), 0 );
985985
long i = futures.stream().filter( Future::isDone ).count();

gemma-core/src/main/java/ubic/gemma/persistence/service/expression/experiment/ExperimentalDesignDaoImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package ubic.gemma.persistence.service.expression.experiment;
2020

21-
import org.apache.commons.lang3.RandomUtils;
21+
import org.apache.commons.lang.math.RandomUtils;
2222
import org.hibernate.SessionFactory;
2323
import org.hibernate.criterion.Restrictions;
2424
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,7 +28,7 @@
2828
import ubic.gemma.persistence.service.AbstractDao;
2929

3030
import javax.annotation.Nullable;
31-
import java.util.List;
31+
import java.util.Random;
3232

3333
/**
3434
* @see ubic.gemma.model.expression.experiment.ExperimentalDesign
@@ -79,7 +79,7 @@ public ExperimentalDesign getRandomExperimentalDesignThatNeedsAttention( Experim
7979
.createQuery( "select distinct ed from ExperimentalDesign ed join ed.experimentalFactors ef "
8080
+ "join ef.factorValues fv where ed.id != :edId and fv.needsAttention = true" )
8181
.setParameter( "edId", excludedDesign.getId() )
82-
.setFirstResult( RandomUtils.nextInt( 0, numThatNeedsAttention.intValue() ) )
82+
.setFirstResult( RandomUtils.nextInt( numThatNeedsAttention.intValue() ) )
8383
.setMaxResults( 1 )
8484
.uniqueResult();
8585
}

gemma-core/src/test/java/ubic/gemma/core/analysis/service/GeneMultifunctionalityPopulationServiceTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919

2020
package ubic.gemma.core.analysis.service;
2121

22+
import org.apache.commons.lang.math.RandomUtils;
2223
import org.apache.commons.lang3.RandomStringUtils;
23-
import org.apache.commons.lang3.RandomUtils;
2424
import org.junit.After;
2525
import org.junit.Before;
2626
import org.junit.Test;
2727
import org.junit.experimental.categories.Category;
2828
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.core.io.ClassPathResource;
3030
import org.springframework.test.annotation.DirtiesContext;
31-
import ubic.gemma.persistence.service.genome.gene.GeneService;
3231
import ubic.gemma.core.ontology.providers.GeneOntologyService;
3332
import ubic.gemma.core.util.test.BaseSpringContextTest;
3433
import ubic.gemma.core.util.test.category.SlowTest;
@@ -44,6 +43,7 @@
4443
import ubic.gemma.model.genome.Taxon;
4544
import ubic.gemma.persistence.service.association.Gene2GOAssociationService;
4645
import ubic.gemma.persistence.service.common.description.ExternalDatabaseService;
46+
import ubic.gemma.persistence.service.genome.gene.GeneService;
4747

4848
import java.io.InputStream;
4949
import java.util.Collection;
@@ -95,7 +95,7 @@ public void setUp() throws Exception {
9595

9696
testTaxon = taxonService.findOrCreate( Taxon.Factory
9797
.newInstance( "foobly" + RandomStringUtils.randomAlphabetic( 2 ),
98-
"doobly" + RandomStringUtils.randomAlphabetic( 2 ), RandomUtils.nextInt( 0, 5000 ), true ) );
98+
"doobly" + RandomStringUtils.randomAlphabetic( 2 ), RandomUtils.nextInt( 5000 ), true ) );
9999

100100
/*
101101
* Create genes

0 commit comments

Comments
 (0)