GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TransactionTest: throttle unbound thread pool to limit resource consu… · hehuelet/objectbox-java@def827d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/objectbox-java-test/src/test/java/io/objectbox
    • TestUtils.java
    • TransactionTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/TestUtils.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/TestUtils.java
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

3434
public class TestUtils {
3535

36+
public static boolean isWindows() {
37+
final String osName = System.getProperty("os.name").toLowerCase();
38+
return osName.contains("windows");
39+
}
40+
3641
public static String loadFile(String filename) {
3742
try {
3843
InputStream in = openInputStream("/" + filename);
Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/TransactionTest.java
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.Executors;
3030
import java.util.concurrent.Future;
3131
import java.util.concurrent.LinkedBlockingQueue;
32+
import java.util.concurrent.ThreadPoolExecutor;
3233
import java.util.concurrent.TimeUnit;
3334
import java.util.concurrent.atomic.AtomicInteger;
3435

@@ -496,7 +497,8 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
496497
.noReaderThreadLocals() // This is the essential flag to make this test work
497498
.build();
498499

499-
// Unbounded thread pool so number of threads run exceeds max readers.
500+
// Unbounded (but throttled) thread pool so number of threads run exceeds max readers.
501+
int numThreads = TestUtils.isWindows() ? 300 : 1000; // Less on Windows; had some resource issues on Windows CI
500502
ExecutorService pool = Executors.newCachedThreadPool();
501503

502504
ArrayList<Future<Integer>> txTasks = new ArrayList<>(10000);
@@ -510,6 +512,9 @@ private void runThreadPoolReaderTest(Runnable runnable) throws Exception {
510512
return txNumber;
511513
}
512514
}));
515+
if (pool instanceof ThreadPoolExecutor && ((ThreadPoolExecutor) pool).getActiveCount() > numThreads) {
516+
Thread.sleep(1); // Throttle processing to limit thread resources
517+
}
513518
}
514519

515520
//Iterate through all the txTasks and make sure all transactions succeeded.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.