我有一个(小)动态网站,它(大致)是一个使用 SQLite 数据库的 Perl CGI 脚本。包 DBI 是 Perl 中使用的抽象层。
大约一周前,我开始看到此错误消息:
dbdimp.c 第 271 行的磁盘 I/O 错误 (10)
由于这是一个运行 Apache 的托管站点,我无法查看硬盘是否(几乎)已满。访问命令“df”被禁用......但我使用(UNIX)shell命令“是> blah”来测试磁盘仍然可以创建新文件。我的数据库非常小——不到 50 KB。
我检查了文件和目录权限:目录和所有父项都是 a+r,a+x(全部 + 读取/可执行)。包含我的 SQLite 数据库文件的目录也是 a+w(全部 + 写入)。数据库文件本身有a+w,a+r(全部+读/写)。
我编写了一个简单的 Perl 程序来测试我可以运行失败的选择查询:它运行良好。
我在数据库上运行了查询“VACUUM”。我再次尝试了我的测试——没有改善。
我将 SQLite 数据库转储为原始 SQL(使用 SQLite shell 命令“.dump”)并重建。我再次尝试了我的测试——没有改善。
有什么建议?我很困惑......通常,上面的列表可以捕获大多数编程/设置错误。
背景:我使用Java类InitialDirContext
访问LDAP目录。 不幸的是,它没有实现interface AutoCloseable
,因此不能在try-with-resources块中使用。
这是我写的原始代码:(受此答案启发)
final Properties props = new Properties();
// Populate 'props' here.
final InitialDirContext context = new InitialDirContext(props);
Exception e0 = null;
try {
// use 'context' here
}
catch (Exception e) {
// Only save a reference to the exception.
e0 = e;
// Why re-throw?
// If finally block does not throw, this exception must be thrown.
throw e;
}
finally {
try {
context.close();
}
catch (Exception …
Run Code Online (Sandbox Code Playgroud) 在整个Google Guava库中,我注意到了使用"一(或两个)加var args"技术的倾向.
例子:
void add(T value, T... moreValueArr)
void add(T value, T value2, T... moreValueArr)
我花了一段时间才弄清楚原因:为了防止使用零args(第一种情况下)或一种arg(第二种情况)调用.
如果在下面的场景A和B之间做出选择,那么进一步扩展这项技术,哪个更好?我希望有深入Java知识的人可以提供洞察力.
情景A :(两种方法)
void add(T... valueArr)
void add(Iterable<? extends T> iterable)
情景B :(三种方法)
void add(T value, T... moreValueArr)
void add(T[] valueArr)
void add(Iterable<? extends T> iterable)
一个想法为什么B可能更好:我注意到许多Java程序员都不知道数组可以直接作为var args传递.因此,B可能提供关于可能性的暗示.
最后,我意识到B有额外的开发,测试和维护开销.请把这些考虑放在一边.
这个问题是我原来问题的一个微妙变化:Java varags方法参数列表与数组
当javax.annotation.Nullable
用于将方法标记为"潜在返回null
值"时,在何处放置@Nullable
注释?在方法上,还是返回类型?
是否有任何技术差异,或者这是一个严格的风格问题?
风格A:
@Nullable
public Object blah() { ... }
Run Code Online (Sandbox Code Playgroud)
风格B:
public @Nullable Object blah() { ... }
Run Code Online (Sandbox Code Playgroud) 在下面的两种样式中,Iterator
分配了一个对象。在迭代之前检查集合是否为空有用吗?我不知道这是否符合“过早优化”的条件。希望对 JVM 垃圾收集器有深入了解的人可以提供见解。
另外,我不知道 Java 编译器如何处理 for-each 循环。我假设样式B会自动转换为样式A。但是......也许包括一张空支票。
循环样式 A
Collection<String> collection = ...
Iterator<String> iter = collection.iterator();
while (iter.hasNext()) {
String value = iter.next();
// do stuff
// maybe call iter.remove()
}
Run Code Online (Sandbox Code Playgroud)
循环样式 B
Collection<String> collection = ...
for (String value : collection) {
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
循环样式 A(修改)
Collection<String> collection = ...
if (!collection.isEmpty()) {
Iterator<String> iter = collection.iterator();
while (iter.hasNext()) {
String value = iter.next();
// do stuff
// maybe …
Run Code Online (Sandbox Code Playgroud) java iteration collections garbage-collection micro-optimization
演示失败的示例代码:
package ia.quant.nextgen.entry;
import com.google.common.collect.ArrayListMultimap;
import java.util.function.Consumer;
/**
* Created by arpeke on 2015-12-18.
*/
public final class SampleMain {
public static void main(String[] argArr) {
final ArrayListMultimap<Void, Void> arrayListMultimap = ArrayListMultimap.create();
arrayListMultimap.clear();
final Consumer<ArrayListMultimap> arrayListMultimapConsumer = ArrayListMultimap::clear;
arrayListMultimapConsumer.accept(arrayListMultimap);
}
}
Run Code Online (Sandbox Code Playgroud)
这是Error
(不Exception
)我看到的:
Exception in thread "main" java.lang.IllegalAccessError:
tried to access class com.google.common.collect.AbstractMapBasedMultimap
from class ia.quant.nextgen.entry.SampleMain
at ia.quant.nextgen.entry.SampleMain.lambda$main$1(SampleMain.java:17)
at ia.quant.nextgen.entry.SampleMain.main(SampleMain.java:18)
Run Code Online (Sandbox Code Playgroud)
我使用的是32位Java 8(v1.8.0_60)和Google Guava v19.0.我的Google-Fu告诉我Google Guice是根本原因,但缺乏可信的解释.(这是一个更大的项目的一部分,该项目还包括通过Apache Maven的Google Guice v3.0.)
示例参考:https://github.com/hierynomus/scannit/issues/7
有人知道吗...?
(最后,我也试过Google Guava …
给定十六进制格式的文字内存地址,如何在C中创建一个指向此内存位置的指针?
我的平台(IBM iSeries)上的内存地址是128位.C类型long long
也是128位.
想象一下,我有一个字符串(char数组)的内存地址,它是: C622D0129B0129F0
我假设正确的C语法直接寻址此内存位置:
const char* const p = (const char* const)0xC622D0129B0129F0ULL
我用ULL
后缀表示unsigned long long literal.
我的内核/平台/操作系统是否允许我这样做是一个不同的问题.我首先想知道我的语法是否正确.
我安装了最新的JDK(1.7.0_21).当我在Eclipse中查看基础类的源代码时,例如java.lang.String
文件顶部的许可证读取:
/*
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
Run Code Online (Sandbox Code Playgroud)
此源代码来自src.zip
JDK发行版附带的文件.
当我看到在源代码在这里: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/lang/String.java?av=f
...我看到了GPL v2.0许可证标题.
/*
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General …
Run Code Online (Sandbox Code Playgroud) 在我过去作为C / C ++程序员的生活中,可能在某些平台和调试器组合上有选择地挂起线程。达到断点后,可以发出命令(或单击GUI中的内容)以对线程进行冰/除冰(挂起/唤醒)。在执行进一步的步骤/下一个/运行/继续命令时,挂起的线程将不执行任何指令。
今天,使用任何JVM或Java IDE都可以做到吗?我使用IntelliJ,但没有看到该功能,也无法通过Google找到任何信息。
澄清:
最后,我意识到“ Java调试器”是一个模糊的术语。在AFAIK中,Sun发布了一种在线调试格式,调试器使用该格式与JVM进行通信。也许每个JVM(IBM,Sun,IcedTea和???)都支持不同的调试功能,但是我只熟悉Sun / Oracle JVM。
我对在Java中的线程之间安全地共享数组感到困惑,特别是内存栅栏和关键字synchronized
.
这个Q&A很有帮助,但没有回答我的所有问题:Java数组:synchronized + Atomic*,还是同步的?
以下是演示该问题的示例代码.假设有一个工作线程池填充了SharedTable
via方法add(...)
.完成所有工作线程后,最后一个线程将读取并保存数据.
用于演示此问题的示例代码:
public final class SharedTable {
// Column-oriented data entries
private final String[] data1Arr;
private final int[] data2Arr;
private final long[] data3Arr;
private final AtomicInteger nextIndex;
public SharedTable(int size) {
this.data1Arr = new String[size];
this.data2Arr = new int[size];
this.data3Arr = new long[size];
this.nextIndex = new AtomicInteger(0);
}
// Thread-safe: Called by worker threads
public void addEntry(String data1, int data2, long data3) {
final int index = nextIndex.getAndIncrement();
data1Arr[index] …
Run Code Online (Sandbox Code Playgroud)