Skip to content

Commit

Permalink
Better outline
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Jun 20, 2022
1 parent 626f638 commit a9f39bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ public List<String> quickSort(List<String> allWords) {
return targetArray;
}


/**
* Make Virtual Thread go through states
* RUNNING
* PARKING
* RUNNING
* @param words
* @return
*/
@Override
public String makeTextFromWordFlow(List<String> words) {
return flowManager.readWordFlowBack(words);
Expand Down Expand Up @@ -274,12 +283,19 @@ public List<InterNode> createIntersectionWordList(String sentenceLeft, String se

/**
* An example of an IO operation that doesn't seem to change the behaviour of Virtual Threads.
*
* Goes through state
* RUNNING
* PARKING
* @param words
* @return
*/
@Override
public String saveWords(List<String> words) {
try {
sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
final File tempFile;
try {
tempFile = File.createTempFile("test", "txt");
Expand All @@ -303,13 +319,18 @@ public String saveWords(List<String> words) {
/**
* This method doesn't seem to be doing much, but notice that it is synchronized.
* Synchronized in virtual threads, generates the need to Park threads while they wait
* Makes Virtual Thread go through states
* RUNNING
* PARKING
* PINNED
* RUNNING
*
* @param words
* @return
*/
public synchronized String saveWordsParking(List<String> words) {
try {
sleep(1000);
sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ public Integer call() throws Exception {
log.info("===> Text size is {}", content.length());

performTest(
"Write to 1 file - No Parking - Virtual Thread",
"Write to 1 file - Yield - Virtual Thread",
"saveWordsNio",
"n/a", "n/a",
() -> algorithmManager.saveWords(algorithmManager.findAllUniqueWords("I had problem B, but he understood problem A, then he created problem C out of problem A, said problem C was mine and presented me with a solution to problem C. My original problem was never solved and he ended up getting a promotion.")),
() -> algorithmManager.saveWords(algorithmManager.findAllUniqueWords(content)), 2);

performTest(
"Write to 1 file - Parking - Virtual Thread",
"Write to 1 file - Pinning - Yield - Virtual Thread",
"saveWordsNio",
"n/a", "n/a",
() -> algorithmManager.saveWordsParking(algorithmManager.findAllUniqueWords("When I make meetings I always make sure they are technical, but tell me what did that with you")),
Expand Down

0 comments on commit a9f39bb

Please sign in to comment.