本文整理汇总了Scala中java.util.ConcurrentModificationException类的典型用法代码示例。如果您正苦于以下问题:Scala ConcurrentModificationException类的具体用法?Scala ConcurrentModificationException怎么用?Scala ConcurrentModificationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConcurrentModificationException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MapDBStorage
//设置package包名称以及导入依赖的类
package one.lockstep.util.storage.mapdb
import java.util.ConcurrentModificationException
import one.lockstep.util.storage.TransactionalStorage
import TransactionalStorage._
import org.mapdb.{DB, TxMaker}
class MapDBStorage(txMaker: TxMaker) extends TransactionalStorage {
private[this] case class Schema(db: DB) {
lazy val leaseCounter = db.atomicLong("lease-counter")
lazy val data = db.namedMap("data")
lazy val acquiredByLease = db.namedNumberMap("leases")
}
private lazy val boundStorage = {
val boundStorage = txMaker.bind(db => Schema(db))
// init
boundStorage.tx { schema =>
schema.leaseCounter
schema.data
schema.acquiredByLease
}
boundStorage
}
private def tx[A](f: Schema => A) = Lock.synchronized { boundStorage.tx(f) }
private def ro[A](f: Schema => A) = boundStorage.ro(f)
private def keyOf(coords: Coordinates): String = s"${coords.collectionName}.${coords.itemId}"
@throws[ConcurrentModificationException]
override def save(lease: Lease, view: View): Unit = tx { schema =>
view.entries.foreach { case (coord, value) =>
val key = keyOf(coord)
val currentLease = schema.acquiredByLease.getOrElse(key, -1)
if (lease.value != currentLease) throw new ConcurrentModificationException(s"obsolete lease for $coord")
schema.acquiredByLease.put(key, lease.value)
value match {
case None => schema.data.remove(key) // we remove the data but keep the lease..
case Some(bytes) => schema.data.put(key, bytes)
}
}
}
override def clear(): Unit = tx { schema =>
schema.acquiredByLease.clear()
schema.data.clear()
schema.leaseCounter.set(0)
}
}
private object Lock