Java性能计时库

我经常在System.nanoTime()对中包装代码以便对其进行计时。 就像是: long start = System.nanoTime(); methodToBeTimed(); long elapsedTime = System.nanoTime() – start; 有什么好的计时库可以解决这个问题吗? 还将接受自行开发的代码。 NB 分析器在这里不是解决方案,因为我想在unit testing中强制执行一些时间限制,所以我想以编程方式对方法进行计时。

从日志文件中提取java堆栈跟踪的工具

是否有任何工具可以提取出现在日志文件中的堆栈跟踪列表,并且可能会计算唯一的堆栈跟踪列表? 编辑 :我会做一些不基于GUI的东西,并在后台运行并提供某种报告。 我从很多环境收集了很多日志,只是想快速浏览一下。

Application Server JDBC资源的DataSource或ConnectionPoolDataSource

在应用程序服务器中创建JNDI JDBC连接池时,我总是将类型指定为javax.sql.ConnectionPoolDataSource 。 我从来没有真正给过太多考虑,因为在非汇集时更喜欢汇集连接似乎总是很自然。 但是,在查看一些示例( 特别是Tomcat )时,我注意到它们指定了javax.sql.DataSource 。 此外,似乎有maxIdle和maxWait设置给人的印象是这些连接也是合并的。 无论选择何种类型的数据源,Glassfish都允许使用这些参数。 javax.sql.DataSource是否在应用程序服务器(或servlet容器)中池化? 在javax.sql.DataSource选择javax.sql.ConnectionPoolDataSource有什么优点(如果有的话)(反之亦然)?

无法使用Jar文件查找或加载主类

我正在尝试使用加载jar @echo off java -jar Test.jar pause 随着的表现 Manifest-Version: 1.0 Main-Class: classes.TestClass 在Jar目录中,当我提取它时,我可以清楚地看到classes \ TestClass文件。 编辑: classes.TestClass确实有一个public static void main(String[] args) 。 classes.TestClass Package Deceleration是package classes; 但我仍然收到错误消息 Could not find or load main class classes.TestClass 我经历过这个问题所能找到的一切,但似乎没有任何帮助。 我已经尝试编辑类路径,重做清单,安装新的JRE。 我还应该做什么?

如何增加类Integer从另一个方法引用java中的值

package myintergertest; /** * * @author Engineering */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { //this one does not increment Integer n = new Integer(0); System.out.println(“n=” + n); Increment(n); System.out.println(“n=” + n); Increment(n); System.out.println(“n=” + n); Increment(n); System.out.println(“n=” + n); Increment(n); //this one […]

Spring Boot安全性CORS

我对弹簧安全URL的CORSfilter有问题。 它不会在属于spring sec(登录/注销)的URL上设置Access-Control-Allow-Origin和其他公开的标头,也不会被Spring Security过滤。 这是配置。 CORS: @Configuration @EnableWebMvc public class MyWebMvcConfig extends WebMvcConfigurerAdapter { ********some irrelevant configs************ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping(“/*”).allowedOrigins(“*”).allowedMethods(“GET”, “POST”, “OPTIONS”, “PUT”) .allowedHeaders(“Content-Type”, “X-Requested-With”, “accept”, “Origin”, “Access-Control-Request-Method”, “Access-Control-Request-Headers”) .exposedHeaders(“Access-Control-Allow-Origin”, “Access-Control-Allow-Credentials”) .allowCredentials(true).maxAge(3600); } } 安全: @Configuration @EnableWebSecurity public class OAuth2SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { […]

使用谷歌自定义搜索API的Java代码

任何人都可以分享一些java代码开始使用谷歌搜索API。我在互联网上搜索但没有找到任何适当的文档或良好的示例代码。我找到的代码似乎没有工作。如果有人,我将感激不尽可以帮助我。(我已经获得了API密钥和自定义搜索引擎ID)。 谢谢。

递归流

我想使用Java 8以递归方式列出计算机上的所有文件。 Java 8提供了一个listFiles方法,该方法返回所有文件和目录,但没有递归。 如何使用它来获取完整的递归文件列表(不使用变异集合)? 我已经尝试了下面的代码,但它只有一个深度: static Function<Path, Stream> listFiles = p -> { if (p.toFile().isDirectory()) { try { return Files.list(p); } catch (Exception e) { return Stream.empty(); } } else { return Stream.of(p); } }; public static void main(String[] args) throws IOException { Path root = Paths.get(“C:/temp/”); Files.list(root).flatMap(listFiles).forEach(System.out::println); } 并使用return Files.list(p).flatMap(listFiles); 不编译(不确定原因)…… 注意:我对涉及FileVisitors或外部库的解决方案不感兴趣。

JSch中’shell’通道和’exec’通道之间有什么区别

我希望能够将Java应用程序中表示为字符串的许多连续命令发送到SSH服务器以供执行。 我应该使用: Channel channel = session.openChannel(“shell”); -要么- Channel channel = session.openChannel(“exec”);

Eclipse缺少动作集

打开Eclipse时遇到问题。 在错误日志中它说: unable to find action set org.eclipse.wb.core.ui.actionset org.eclipse.rse.core.search.searchActionSet org.eclipse.rse.core.search.searchActionSet org.eclipse.mylyn.doc.actionSet org.eclipse.mylyn.context.ui.actionSet 我正在使用Eclipse juno(版本4.2),我的ADT是版本20和Java 1.6你知道我应该做什么吗?