本文整理汇总了Scala中java.util.concurrent.LinkedBlockingDeque类的典型用法代码示例。如果您正苦于以下问题:Scala LinkedBlockingDeque类的具体用法?Scala LinkedBlockingDeque怎么用?Scala LinkedBlockingDeque使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkedBlockingDeque类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: LogProcessor
//设置package包名称以及导入依赖的类
package executable
import java.io.FileWriter
import java.text.{DateFormat, SimpleDateFormat}
import java.util.Date
import java.util.concurrent.LinkedBlockingDeque
import exonode.clifton.config.ProtocolConfig
import exonode.clifton.node.SpaceCache
import exonode.clifton.node.entries.ExoEntry
import exonode.clifton.signals.Log.LogType
object LogProcessor extends Thread {
setDaemon(true)
private val LogFile: String = "log.cfv"
private val IntervalTime = 1000
private val MaxLogsCalls = 20
private val logTemplate = ExoEntry[LogType](ProtocolConfig.LogMarker, null)
private val dateFormat: DateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
private val logs = new LinkedBlockingDeque[LogType]()
private val analyseFile = new SystemAnalyser(2, logs)
override def run(): Unit = {
val space = SpaceCache.getSignalSpace
println("LogProcessor Started...")
analyseFile.start()
while (true) {
val res: Iterable[ExoEntry[LogType]] = space.takeMany(logTemplate, MaxLogsCalls)
if (res.nonEmpty) {
val file: FileWriter = new FileWriter(LogFile, true)
val date: Date = new Date()
for (exoEntry <- res) {
val log = exoEntry.payload
logs.push(log)
file.write(dateFormat.format(date) + ProtocolConfig.LogSeparator + log.logType +
ProtocolConfig.LogSeparator + log.message + "\n")
}
file.close()
} else
Thread.sleep(IntervalTime)
}
}
def main(args: Array[String]): Unit = {
if (args.length > 0)
SpaceCache.signalHost = args(0)
LogProcessor.start()
LogProcessor.join()
}
}
示例2: EventDeliveryThread
//设置package包名称以及导入依赖的类
package com.twitter.finagle.serverset2.client
import java.util.concurrent.LinkedBlockingDeque
import com.twitter.util.{Monitor, Updatable}
private[client] object EventDeliveryThread
extends Thread("com.twitter.zookeeper.client.internal event delivery") {
private val q = new LinkedBlockingDeque[(Updatable[WatchState], WatchState)]
def offer(u: Updatable[WatchState], s: WatchState) {
q.offer((u, s))
}
override def run() {
while (true) {
val (u, s) = q.take()
try {
u() = s
} catch {
case exc: Throwable => Monitor.handle(exc)
}
}
}
setDaemon(true)
start()
}