File tree Expand file tree Collapse file tree 5 files changed +73
-1
lines changed
core-kotlin-concurrency-3
src/main/java/com/baeldung/comparedelays
core-kotlin-date-time/src/test/kotlin/com/baeldung/currentdatetime Expand file tree Collapse file tree 5 files changed +73
-1
lines changed Original file line number Diff line number Diff line change
1
+ ## Core Kotlin Concurrency
2
+
3
+ This module contains articles about concurrency in Kotlin.
4
+
5
+ ### Relevant articles:
Original file line number Diff line number Diff line change
1
+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3
+ <modelVersion >4.0.0</modelVersion >
4
+ <parent >
5
+ <groupId >com.baeldung</groupId >
6
+ <artifactId >core-kotlin-modules</artifactId >
7
+ <version >1.0.0-SNAPSHOT</version >
8
+ </parent >
9
+
10
+ <artifactId >core-kotlin-concurrency-3</artifactId >
11
+ <packaging >jar</packaging >
12
+
13
+ <name >core-kotlin-concurrency-3</name >
14
+ <url >http://maven.apache.org</url >
15
+
16
+ <properties >
17
+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
18
+ </properties >
19
+
20
+ <dependencies >
21
+ <dependency >
22
+ <groupId >junit</groupId >
23
+ <artifactId >junit</artifactId >
24
+ <version >3.8.1</version >
25
+ <scope >test</scope >
26
+ </dependency >
27
+ </dependencies >
28
+ </project >
Original file line number Diff line number Diff line change
1
+ package com.baeldung.comparedelays
2
+
3
+ import kotlinx.coroutines.delay
4
+ import kotlinx.coroutines.runBlocking
5
+ import kotlinx.coroutines.*
6
+
7
+ val lock = Object ()
8
+
9
+ fun main () {
10
+ runBlocking(Dispatchers .Default ) {
11
+ launch(Dispatchers .IO ) {
12
+ testWaitThread1()
13
+ }
14
+ launch(Dispatchers .IO ) {
15
+ testWaitThread2()
16
+ }
17
+ }
18
+ }
19
+
20
+ fun testWaitThread1 () = synchronized(lock) {
21
+ lock.wait()
22
+ println (" Print first" )
23
+ }
24
+
25
+ fun testWaitThread2 () = synchronized(lock) {
26
+ println (" Print second" )
27
+ lock.notify()
28
+ }
29
+ fun sleepMethod () {
30
+ println (" Thread 1 is sleeping..." )
31
+ Thread .sleep(2000 ) // Sleep for 2 seconds
32
+ println (" Thread 1 woke up!" )
33
+ }
34
+ fun delayMethod () = runBlocking {
35
+ println (" Coroutine 1 is delaying..." )
36
+ delay(2000 ) // Delay for 2 seconds
37
+ println (" Coroutine 1 resumed!" )
38
+ }
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ class CurrentDateTImeUnitTest {
53
53
54
54
val current = LocalDateTime .of(
55
55
calendar.get(Calendar .YEAR ),
56
- calendar.get(Calendar .MONTH + 1 ) ,
56
+ calendar.get(Calendar .MONTH ) + 1 ,
57
57
calendar.get(Calendar .DAY_OF_MONTH ),
58
58
calendar.get(Calendar .HOUR_OF_DAY ),
59
59
calendar.get(Calendar .MINUTE ),
Original file line number Diff line number Diff line change 61
61
<module >core-kotlin-string-conversions</module >
62
62
<module >core-kotlin-files</module >
63
63
<module >core-kotlin-operators</module >
64
+ <module >core-kotlin-concurrency-3</module >
64
65
</modules >
65
66
66
67
</project >
You can’t perform that action at this time.
0 commit comments