This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Imperative way | |
let rect1 = {a: 50, b: 30}; | |
let calculateRectArea = (rect) => { | |
return rect.a * rect.b; | |
} | |
console.log(calculateRectArea(rect1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Race condition solved example | |
* | |
* The same as race condition example, but with a particular synchronized inc() method to increment z | |
* | |
* Result: After program termination z is always 10000 | |
*/ | |
public class RaceConditionSolvedExample { | |
static int z; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Race condition example | |
* | |
* Creates a high number of threads and lets each increase a static int variable. | |
* | |
* Result: In most cases, the variable's value isn't 10000 after the program's finished, but a bit below. | |
*/ | |
public class RaceConditionExample { | |
static int z; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple thread example (without synchronized Sysout) | |
* | |
* Creates a certain number of threads and lets each thread print out a message and its index in the array. The | |
* difference from the ThreadExample.java is, that here we do not build on the synchronized possibility to output | |
* strings but write an own method to printout each character in a string. | |
* | |
* Result: Letter salad :D | |
*/ | |
public class ThreadExampleSysout { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple thread example | |
* | |
* Creates a certain number of threads and lets each thread print out a message and its index in the array. | |
* | |
* Result: The outputs aren't in the order the threads were created. | |
*/ | |
public class ThreadExample { | |
public static void main(String[] args) { |