我有一个运行过程的对象:
object MyObject {
def apply(fullFileName: String, recordId: Long): Unit = Future {
import scala.sys.process.Process
Process(s"someProcess $fullFileName").!!
} onComplete {
case util.Success(x) =>
//insert result into db
//update status in db
case util.Failure(e) => //log the result
}
}
def getNextId() = ... //returns the incremented current id from db
它的召唤,例如:
val list = List(...)
list foreach (MyObject(_, getNextId()))
//insert default value into db
假设不会有2个同名文件。
这段代码实际上是线程安全的吗?它可能是。你的想法?但我不确定getNextId().