小编use*_*180的帖子

DateTimeFormatter 的日期格式问题

我有以下格式的日期:1/1/2020 3:4:7 AM我正在尝试使用DateTimeFormatter.

我有以下带有格式化程序的代码来解析它,但它不起作用。

LocalDateTime date = LocalDateTime.parse("1/1/2020 3:4:7 AM", DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a"));
Run Code Online (Sandbox Code Playgroud)

我收到以下异常:

java.time.format.DateTimeParseException: Text '1/1/2020 3:4:7 AM' could not be parsed at index 0

谁能帮我?

java java-time localdatetime datetimeformatter java.time.localdatetime

4
推荐指数
1
解决办法
477
查看次数

将Iterator [String]转换为String

我有一个Iterator [String],我想在Scala中转换为String.我希望以下工作,但我没有输出.我究竟做错了什么?

val it = Iterator("a", "number", "of", "words")
val combined = "";

while (it.hasNext){
   combined = combined + it.next()
}
println(combined)
Run Code Online (Sandbox Code Playgroud)

scala

3
推荐指数
1
解决办法
3085
查看次数

使用子进程输出到HDFS中的文件

我有一个逐行读取文本的脚本,稍微修改一行,然后将该行输出到一个文件.我可以将文本读入文件中,问题是我无法输出文本.这是我的代码.

cat = subprocess.Popen(["hadoop", "fs", "-cat", "/user/test/myfile.txt"], stdout=subprocess.PIPE)
for line in cat.stdout:
    line = line+"Blah";
    subprocess.Popen(["hadoop", "fs", "-put", "/user/test/moddedfile.txt"], stdin=line)
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误.

AttributeError: 'str' object has no attribute 'fileno'
cat: Unable to write to output stream.
Run Code Online (Sandbox Code Playgroud)

python subprocess hdfs

1
推荐指数
1
解决办法
4761
查看次数

异步调用两个Java方法

我有以下代码正在调用两个Web服务。这两个Web服务都返回非常大的响应,因此响应要花相当长的时间(一个Web服务请求为8秒,另一个为12秒)。由于请求是串行而不是并行运行的,因此总执行时间为20秒。

有什么方法可以修改我的代码以异步请求两个Web服务,并且能够在比当前花费的20秒更短的12秒时间内处理响应?

String listOfCities;
String listOfCountries; 

try {
    listOfCities = service.getListOfCities(host+"service/cities");
    listOfCountries = service.getListOfCountries(host+"service/countries");
} catch (Exception e) {
    log.error("Failed to read service: " + e);
}
Run Code Online (Sandbox Code Playgroud)

**感谢您的答复,我觉得这不是重复的,因为我想停止执行我正在执行的两个线程,直到两个线程都收到了结果。下面的解决方案表明了这一点。**

java multithreading asynchronous

1
推荐指数
2
解决办法
1008
查看次数

在输出参数中包含多个计数来改进存储过程

我有一个存储过程,该过程返回许多OUT参数,这些参数由SELECT COUNT(*)查询结果组成。下面的代码段运行正常,但似乎很慢。

我最多有30个不同的OUT参数,这意味着我要运行30个独立的查询,这可能就是为什么查询运行如此缓慢的原因。

有人对我如何加速此代码有任何建议吗?

PROCEDURE get_counts(
   count1 OUT INT,
   count2 OUT INT,
   count3 OUT INT,
   .. etc.
) IS 
   l_count1 INT;
   l_count2 INT;
   l_count3 INT;
   .. etc.
BEGIN
   SELECT COUNT(*) INTO l_count1 from table1 where condition_blah;
   SELECT COUNT(*) INTO l_count2 from table1 where condition_blah;
   SELECT COUNT(*) INTO l_count3 from table1 where condition_blah;
   ... etc

   count1 := l_count1;
   count2 := l_count2;
   count3 := l_count3;
   .. etc
END get_counts;
Run Code Online (Sandbox Code Playgroud)

sql oracle plsql stored-procedures

0
推荐指数
1
解决办法
50
查看次数