java-8

Is there any way to represent infinite future / end of time in Java?

冷暖自知 提交于 2020-01-16 17:08:31
问题 Until now I've been using Instant.MAX to mean infinite future or end of time. For example when calculating the minimum timestamp of a collection of timestamps: Iterator<Instant> it = .... Instant minTs = Instant.MAX; while(it.hasNext()) { Instant curr = it.next(); minTs = curr.isBefore(minTs) ? curr : minTs; } But I realized that there are several issues with using Instant.MAX to represent "infinite future": Instant.MAX is not the same as OffsetDateTime.MAX Instant.MAX.toEpochMilli() raises

Connection is not associated with managed connection

让人想犯罪 __ 提交于 2020-01-16 08:38:55
问题 I'm migrating my application from java 7 to java 8 therefore migrating jboss 7.2 to wildfly 8. Hibernate 3.2.6ga is being used in my application. In the older version below code is running fine as conn value is not changing but with jdk8 and wildfly its causing issue. public static void methodName(final org.hibernate.Session session) throws java.sql.SQLException, Exception { StringBuilder queryString= null; PreparedStatement pstmt = null; Connection conn = null; try { queryString.append("sql

Grails Mapping LocalDateTime of Java 8 domain objects to Gorm

让人想犯罪 __ 提交于 2020-01-16 04:50:09
问题 Java 8 gives the java.time API. I am using a grails application, I want to use java.time for properties of my domain classes. I need to map for instance the LocalDateTime to the DATE/DATETIME on GORM which is built on top of Hibernate. How can I persist my mappings? I see a solution, that I can use jadira, and establish static mappings for my attributs. However is there another way? Please any help is appreciated. 回答1: You can use the user type mapping. See the docs. That should remove the

Pattern matching in Thousands of files

有些话、适合烂在心里 提交于 2020-01-16 00:49:11
问题 I've a regex pattern of words like welcome1|welcome2|changeme ... which I need to search for in thousands of files (varies between 100 to 8000) ranging from 1KB to 24 MB each, in size. I would like to know if there's a faster way of pattern matching than doing what I have been trying. Environment: jdk 1.8 Windows 10 Unix4j Library Here's what I tried till now try (Stream<Path> stream = Files.walk(Paths.get(FILES_DIRECTORY)) .filter(FilePredicates.isFileAndNotDirectory())) { List<String>

How to force Java applet to load using TLS1.0 / TLS1.1

情到浓时终转凉″ 提交于 2020-01-15 12:46:07
问题 I have an web application from which multiple users loads a Java applet. Now there is a problem that the loadbalancer does not support TLS1.2 which is the default for Java8 and it seems that Java8 does not automatically try lower version. How can I force the applet to be loaded using TLS 1.0/1.1? I have tried to put this into the <applet>: <PARAM name="java_arguments" value="-Dhttps.protocols=TLSv1"> Any help is appreciated, not very keen on solution where hundreds of users need to configure

How to use Java regex or Java streams for the given string pattern and create a map out of it

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-15 11:04:47
问题 I have a string with the following pattern, String test = "name=ravi,age=30,id=1;name=teja,age=32,id=2"; As you can see above, ";" is used to separate persons and "," is used to separate person's attributes and "=" to map the values of those attributes. I would like to convert the above string into a Map<String, Map<String, String>> where the key for the outer map is the id and the key for the inner map is the name. Given that it is always guaranteed to have unique ids and names across the

How to use Java regex or Java streams for the given string pattern and create a map out of it

会有一股神秘感。 提交于 2020-01-15 11:04:00
问题 I have a string with the following pattern, String test = "name=ravi,age=30,id=1;name=teja,age=32,id=2"; As you can see above, ";" is used to separate persons and "," is used to separate person's attributes and "=" to map the values of those attributes. I would like to convert the above string into a Map<String, Map<String, String>> where the key for the outer map is the id and the key for the inner map is the name. Given that it is always guaranteed to have unique ids and names across the

Proper way to adapt an exception with CompletableFuture

霸气de小男生 提交于 2020-01-15 10:09:57
问题 I am working on chaining CompletableFuture to adapt an exception. While I have something that is working, I don't understand why it works. @Test public void futureExceptionAdapt() throws ExecutionException, InterruptedException { class SillyException extends Exception { } class AdaptedException extends Exception { AdaptedException(SillyException silly) { } } CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> { sleepForThreeSeconds(); if (true) throw new

Why is garbage collection log Metaspace value different from provided flag?

本秂侑毒 提交于 2020-01-15 08:03:07
问题 I am running a server app on Java 8 with the below flags: -XX:GCLogFileSize=2097152 -XX:InitialBootClassLoaderMetaspaceSize=33554432 -XX:InitialHeapSize=1610612736 -XX:MaxHeapSize=1610612736 -XX:MaxMetaspaceSize=1073741824 -XX:MetaspaceSize=536870912 -XX:NumberOfGCLogFiles=5 -XX:+PrintGC -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+UseCompressedClassPointers -XX:

Java8 + Jcraft = Key is too long for this algorithm

社会主义新天地 提交于 2020-01-15 07:37:26
问题 We are using JCraft / Jsch for sftp file transfer. http://www.jcraft.com/jsch This has worked excellent for several years with Java6 and Java 7. But then we upgraded to Java 8 and it worked fine in our test environment, but it failed in our QA environment. Then it failed against a remote SFTP server. This SFTP server uses 'SSH-2.0-4.2.0.21 SSH Secure Shell Windows NT Server' We have no control over this server. I googled a little and found out that some suggests that the source of the problem