我正在尝试一些关于String Pool的性能基准测试.但是,预计结果不会出现.
我做了3个静态方法
我的期望是(1.最快 - > 3.最慢)
但基准测试显示"Te"+"st"比"Test"快一点.
new String(): 141677000 ns
"Test" : 1148000 ns
"Te"+"st" : 1059000 ns
new String(): 141253000 ns
"Test" : 1177000 ns
"Te"+"st" : 1089000 ns
new String(): 142307000 ns
"Test" : 1878000 ns
"Te"+"st" : 1082000 ns
new String(): 142127000 ns
"Test" : 1155000 ns
"Te"+"st" : 1078000 ns
...
Run Code Online (Sandbox Code Playgroud)
这是代码:
import java.util.concurrent.TimeUnit;
public class StringPoolPerformance {
public static long perform0() {
long start = System.nanoTime();
for …
Run Code Online (Sandbox Code Playgroud) 我想开始看一下JMH,由于某些原因我无法运行基准测试.让我解释一下我的尝试:
定义pom.xml如:
下载了一些官方的JMH示例.作为示例,我选择哪个非常简单并且是一个好的起点:http: //hg.openjdk.java.net/code-tools/jmh/file/0c58dc4fcf17/jmh-samples/src/main/java/org/openjdk /jmh/samples/JMHSample_01_HelloWorld.java
但是这会产生输出:
Exception in thread "main" No benchmarks to run; check the include/exclude regexps.
at org.openjdk.jmh.runner.Runner.run(Runner.java:155)
at org.openjdk.jmh.samples.JMHSample_01_HelloWorld.main(JMHSample_01_HelloWorld.java:90)
Run Code Online (Sandbox Code Playgroud)
我用google搜索,似乎上面的例子应该可行,但对我来说情况并非如此.我也尝试通过阅读来解决这个问题,但这对我来说似乎不起作用:
我试图将生成的类手动移动到/ META-INF/MicroBenchmarks但是这会产生以下错误:
Exception in thread "main" java.lang.IllegalStateException: Mismatched format for the line: JMHSample_01_HelloWorld.class
at org.openjdk.jmh.runner.BenchmarkRecord.<init>(BenchmarkRecord.java:92)
at org.openjdk.jmh.runner.MicroBenchmarkList.find(MicroBenchmarkList.java:133)
at org.openjdk.jmh.runner.Runner.run(Runner.java:150)
at JMHSample_01_HelloWorld.main(JMHSample_01_HelloWorld.java:80)
Run Code Online (Sandbox Code Playgroud)似乎JMH应该在/ META-INF/MicroBenchmarks中产生一些有效的行 - 意味着在这个文件夹中不应该生成java类文件,对吗?
任何人都可以帮我找到错误吗?谢谢.
我遇到了Hibernate(4.3.0)的问题,其中单向@OneToMany返回重复项。
我的数据库结构(带有InnoDB的MySQL)的“ entry”表与“ entry_address”表具有1:N的关系。“ entry”表是主表,“ entry_address”是“ entry”表的子表。
CREATE TABLE IF NOT EXISTS `entry` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(500) NOT NULL,
`active` int(1) NOT NULL DEFAULT '0',
`modifiedTS` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`createdTS` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
INSERT INTO `entry` (`id`, `name`, `active`, `modifiedTS`, `createdTS`) VALUES
(1, 'Test1', 0, '2012-11-05 13:41:03', '2012-11-01 10:11:22'),
(2, 'Test2', 1, '2012-11-05 11:19:37', '2012-11-01 10:11:33'),
(3, …
Run Code Online (Sandbox Code Playgroud) 我遇到一个问题,因为Hibernate(4.1.8.FINAL)返回一个具有NULL值的列表(单向OneToMany映射).
我得到的是: 我得到一个大小为21的List,其中EntryAddress是第10个索引,第二个Entry Address是第20个索引.
Entry [addresses=[null, null, null, null, null, null, null, null, null, null, EntryAddress [id=5, entryId=3, precedence=10, line=Line 3.1], null, null, null, null, null, null, null, null, null, EntryAddress [id=6, entryId=3, precedence=20, line=Line 3.2]]]
Run Code Online (Sandbox Code Playgroud)
我的期望 - 我希望List只有两个EntryAddress对象:
Entry [addresses=[EntryAddress [id=5, entryId=3, precedence=10, line=Line 3.1], EntryAddress [id=6, entryId=3, precedence=20, line=Line 3.2]]]
Run Code Online (Sandbox Code Playgroud)
这是最小的源代码:
@Entity
@Table(name = "entry")
public class Entry {
...
@OneToMany(fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "entry_id")
@OrderColumn(name = "precedence")
private List<EntryAddress> addresses;
...
}
Run Code Online (Sandbox Code Playgroud)
@Entity …
Run Code Online (Sandbox Code Playgroud) 解压缩文件我遇到了一个奇怪的问题,我正在考虑使用charset UTF-8.我正在使用Guava库.
public static byte[] gzip(final CharSequence cs, final Charset charset) throws IOException {
final ByteArrayOutputStream os = new ByteArrayOutputStream(cs.length());
final GZIPOutputStream gzipOs = new GZIPOutputStream(os);
gzipOs.write(charset.encode(CharBuffer.wrap(cs)).array());
Closeables.closeQuietly(gzipOs);
return os.toByteArray();
}
public static boolean gzipToFile(final CharSequence from, final File to, final Charset charset) {
try {
Files.write(StreamUtils.gzip(from, charset), to);
return true;
} catch (final IOException e) {
// ignore
}
return false;
}
public static String gunzipFromFile(final File from, final Charset charset) {
String str = null;
try {
str …
Run Code Online (Sandbox Code Playgroud)