数据库中有太多表.我怎样才能显示具有某些模式的表格?或者有没有办法在shell命令中像"| more"那样进行分页?
如果是scala函数
def A(): Either[Exception, ArrayBuffer[Int]] = {
...
}
Run Code Online (Sandbox Code Playgroud)
什么应该是处理返回结果的正确方法?
val a = A()
和?
我使用以下代码来读取数据.它抛出java.nio.charset.MalformedInputException.我可以正常打开的文件,但它确实包含非ascii字符.无论如何我可以解决这个问题吗?
Source.fromInputStream(stream).getLines foreach { line =>
// store items on the fly
lineParser(line.trim) match {
case None => // no-op
case Some(pair) => // some-op
}
}
stream.close()
Run Code Online (Sandbox Code Playgroud)
流构造代码在这里:
def getStream(path: String) = {
if (!fileExists(path)) {
None
} else {
val fileURL = new URL(path)
val urlConnection = fileURL.openConnection
Some(urlConnection.getInputStream())
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个大型数组可供多个线程访问.单锁效率不高.在java或scala中有一个范围锁类吗?
我想创建一个hashmap来存储参数名称及其值.然而,参数具有不同的类型.我可以使用HashMap [String,Any],但我不知道它们以后是哪种类型.反正我可以恢复类型信息吗?或者有更好的存储方式吗?
Object A {
def a = { something}
}
Run Code Online (Sandbox Code Playgroud)
// I've import A, but still have error message: not found: type A
val x = mock[A]
Run Code Online (Sandbox Code Playgroud) 似乎memcache客户端不支持UTF-8字符串作为其密钥.但我必须使用i18n.无论如何要解决它?
java.lang.IllegalArgumentException:Key包含无效字符:net.spy.memcached.MemcachedClient.addOp中net.spy.memcached.MemcachedClient.validateKey(MemcachedClient.java:232)上的``HK:00:A Kung Wan''( MemcachedClient.java:254)
这是scala的代码段.我将超时设置为100毫克.在10000个循环中,其中106个循环超过100个,没有抛出异常.最大的一个甚至是135个.出现这种情况的原因是什么?
for (j <- 0 to 10000) {
total += 1
val executor = Executors.newSingleThreadExecutor
val result = executor.submit[Int](new Callable[Int] {
def call = try {
Thread.sleep(95)
for (i <- 0 to 1000000) {}
4
} catch {
case e: Exception => exception1 += 1
5
}
})
try {
val t1 = Calendar.getInstance.getTimeInMillis
result.get(100, TimeUnit.MILLISECONDS)
val t2 = Calendar.getInstance.getTimeInMillis
println("timediff = " + (t2 - t1).toString)
} catch {
case e: Exception => exception2 += 1
}
}
Run Code Online (Sandbox Code Playgroud)