我的程序使用Java Scripting API并且可以同时评估一些脚本.他们不使用共享脚本对象,绑定或上下文,但可以使用相同ScriptEngine和CompiledScript对象.我看到Java 8中的Oracle Nashorn实现不是多线程的,ScriptEngineFactory.getParameter('THREADING')返回null文档所说的内容:
引擎实现不是线程安全的,不能用于在多个线程上并发执行脚本.
这是否意味着我应该ScriptEngine为每个线程创建一个单独的实例?此外,文档没有说明CompiledScript并发使用,但:
每个CompiledScript都与ScriptEngine相关联
可以假设CompiledScript线程安全依赖于相关ScriptEngine,即我应该CompiledScript为Nashorn的每个线程使用单独的实例.
如果我应该,对于这个(我认为非常常见的)案例,使用ThreadLocal,池或其他什么是适当的解决方案?
final String script = "...";
final CompiledScript compiled = ((Compilable)scriptEngine).compile(script);
for (int i=0; i<50; i++) {
Thread thread = new Thread () {
public void run() {
try {
scriptEngine.eval(script, new SimpleBindings ()); //is this code thread-safe?
compiled.eval(new SimpleBindings ()); //and this?
}
catch (Exception e) { throw new RuntimeException …Run Code Online (Sandbox Code Playgroud) 这段代码:
public static void f(String[] args) {}
public static void f(Integer[] args) {}
public static void main(String[] args)
{
f(Stream.of("xxx").toArray(i -> new String[i]));
}
Run Code Online (Sandbox Code Playgroud)
使用jdk8u45编译成功但jdk8u60会输出以下错误:
Error:(17, 9) java: reference to f is ambiguous
both method f(java.lang.String[]) in type_infer.Test and method f(java.lang.Integer[]) in type_infer.Test match
Run Code Online (Sandbox Code Playgroud)
它是否遵循JSL,为什么编译器无法解析重载方法?这是jdk8u45中的固定错误吗?
我有一个Timestamp和Date变量,我想比较它的相等性(当然只有日期部分).令我惊讶的是,构造函数Date(long)节省了时间部分,所以这段代码不正确:
date = resultSet.getDate(1);
timestamp = resultSet.getTimestamp(2);
//...
if (date.equals(new Date (timestamp.getTime())) ...
Run Code Online (Sandbox Code Playgroud)
我用以下代码解决这个问题:
DateFormat dateFormat = new SimpleDateFormat ("yyyyMMdd");
if (date.equals(dateFormat.parse(dateFormat.format(timestamp)))) ...
Run Code Online (Sandbox Code Playgroud)
或者我可以在sql查询中将时间戳转换为日期,但我也需要时间戳表示.有没有更好的方法来从时间戳中删除时间部分.
IntelliJ IDEA在最新版本中具有内置的Web服务器,当我对某些HTML文件使用“在浏览器中打开”命令时,该服务器可以工作。因此,URL看起来像:
http://localhost:63342/file.html
Run Code Online (Sandbox Code Playgroud)
我想查看一个file://基于URL的URL(例如,因为Web服务器未链接同一个目录中的同级文件),但是我找不到任何选择。因此,如何禁用此Web服务器,或者可能在哪里可以找到另一个命令直接在浏览器中查看文件?当然,我可以单击“复制路径”并将其粘贴到浏览器的网址栏中,但我正在寻找一种更方便的方法。
我在 flex 容器中有不同大小的项目,我想根据内容显示在不同宽度的几列中。flex-flow: column wrap固定容器高度对我很有用,但我有固定的容器宽度,并希望高度取决于内容。即我想要尽可能多的列宽度。例如,它的外观:
.container {
height: 80px;
display: flex;
align-items: flex-start;
justify-content: flex-start;
flex-flow: column wrap;
align-content: left;
}
.container > span {
margin: 3px 12px;
background: #ebd2b5
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<span>Apple</span>
<span>Apricot</span>
<span>Avocado</span>
<span>Banana</span>
<span>Bilberry</span>
<span>Blackberry</span>
<span>Blackcurrant</span>
<span>Blueberry</span>
<span>Boysenberry</span>
<span>Currant</span>
<span>Cherry</span>
<span>Cherimoya</span>
<span>Cloudberry</span>
<span>Coconut</span>
</div>Run Code Online (Sandbox Code Playgroud)
任何使用 CSS 的解决方案?
我想在没有边框和标题栏的窗口客户区中隐藏光标(它是简单的 opengl 应用程序)。所以,函数
ShowCursor(FALSE);
Run Code Online (Sandbox Code Playgroud)
不合适。经过一番搜索winapi,我找到了这个解决方案:
//when create window class for application window
WNDCLASSEX WndClass;
//...
BYTE CursorMaskAND[] = { 0xFF };
BYTE CursorMaskXOR[] = { 0x00 };
WndClass.hCursor = CreateCursor(NULL, 0,0,1,1, CursorMaskAND, CursorMaskXOR);
Run Code Online (Sandbox Code Playgroud)
这是解决这个典型任务的好方法吗?什么方法最好?