Skip to content

Commit 694cd10

Browse files
Replace Synchronized annotations by making the lists Synchronized instead of using a normal ArrayList.
1 parent beef5b9 commit 694cd10

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cache/src/main/kotlin/com/runetopic/cache/store/Js5Store.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.Closeable
77
import java.math.BigInteger
88
import java.nio.ByteBuffer
99
import java.nio.file.Path
10+
import java.util.*
1011

1112
/**
1213
* @author Tyler Telis
@@ -19,14 +20,13 @@ class Js5Store(
1920
parallel: Boolean = false
2021
) : Closeable {
2122
private var storage = Js5DiskStorage(path, parallel)
22-
private val indexes = arrayListOf<Index>()
23+
private val indexes = Collections.synchronizedList<Index>(mutableListOf())
2324

2425
init {
2526
storage.init(this)
2627
indexes.sortWith(compareBy { it.id })
2728
}
2829

29-
@Synchronized
3030
internal fun addIndex(index: Index) {
3131
indexes.forEach { i -> require(index.id != i.id) { "Index with Id={${index.id}} already exists." } }
3232
indexes.add(index)

cache/src/main/kotlin/com/runetopic/cache/store/storage/js5/Js5DiskStorage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.runetopic.cache.store.storage.js5.impl.IdxFile
1111
import com.runetopic.cryptography.toWhirlpool
1212
import java.io.FileNotFoundException
1313
import java.nio.file.Path
14+
import java.util.*
1415
import java.util.concurrent.CountDownLatch
1516
import java.util.concurrent.Executors
1617
import kotlin.io.path.ExperimentalPathApi
@@ -29,7 +30,7 @@ internal class Js5DiskStorage(
2930
) : IStorage {
3031
private var masterIdxFile: IIdxFile
3132
private var datFile: IDatFile
32-
private var idxFiles: ArrayList<IdxFile> = arrayListOf()
33+
private var idxFiles = Collections.synchronizedList<IdxFile>(mutableListOf())
3334
private val logger = InlineLogger()
3435

3536
init {
@@ -96,7 +97,6 @@ internal class Js5DiskStorage(
9697
return datFile.readReferenceTable(index.id, getIdxFile(index.id).loadReferenceTable(group.id))
9798
}
9899

99-
@Synchronized
100100
private fun getIdxFile(id: Int): IdxFile {
101101
idxFiles.find { it.id() == id }?.let { return it }
102102
return IdxFile(id, Path.of("$path/${Constants.MAIN_FILE_IDX}${id}"))

0 commit comments

Comments
 (0)