SlideShare a Scribd company logo
1CONFIDENTIAL
Senior developer
10+ years experience in IT
• 7+ Java-development experience
• 5+ trainer experience
• 3+ system analysis
Interests:
• Messaging
• Functional programming (Clojure,
Scala)
About author
2CONFIDENTIAL
• Parallel Streams can actually slow you down
• The flip-side of Lambda expressions
• Default Methods are distracting
• Checked Exceptions
• Field Access
• Stream API support
• CriptoPro`blem…
• NIO-2 WatchService
• Generics in ENUM`s
AGENDA
3CONFIDENTIAL
Parallel Streams can actually slow you down
• Java 8 brings the promise of parallelism as one of the most anticipated new features. The
.parallelStream() method implements this on collections and streams. It breaks them into
subproblems which then run on separate threads for processing, these can go to different cores and
then get combined when they’re done. This all happens under the hood using the fork/join
framework.
• Ok, sounds cool, it must speed up operations on large data sets in multi-core environments, right?
Stream API in Enterprise Java - Problems
4CONFIDENTIAL
Parallel Streams can actually slow you down
• Let`s test it:
• To sort an array using multiple cores all you have to do is –
– Arrays.parallelSort(numbers);
• To group a collection into different groups based on a specific criteria (e.g. prime and non-prime
numbers)
– Map<Boolean, List> groupByPrimary = numbers.parallelStream()
.collect(Collectors.groupingBy(s -> Utility.isPrime(s)));
• 3 . To filter out values all you have do is –
– Integer[] prims = numbers.parallelStream().filter(s -> Utility.isPrime(s))
.toArray();
Stream API in Enterprise Java - Problems
5CONFIDENTIAL
Parallel Streams can actually slow you down
• https://github.com/takipi/java-8-parallelism-benchmarks
Stream API in Enterprise Java - Problems
6CONFIDENTIAL
Parallel Streams can actually slow you down
• The results were not surprising:
• Quicksort is now 4.7X times faster.
• Grouping is now 5X times faster.
• Filtering is now 5.5X times faster.
• A happy ending? Unfortunately not.
• So what happens under load?
• So far things have been quite peachy, the reason being that there’s little contention between
threads for CPU cycles. That’s an ideal situation, but unfortunately, one that doesn’t happen a
lot in real life. To simulate a scenario which is more on par with what you’d normally see in a
real-world environment I set up a second test. This test runs the same set of algorithms, but
this time executes them on ten concurrent threads to simulate processing ten concurrent
requests performed by a server when it’s under pressure. Each of those requests will then be
handled either sequentially using a traditional approach, or the new Java 8 APIs.
Stream API in Enterprise Java - Problems
7CONFIDENTIAL
Parallel Streams can actually slow you down
• The results:
• Sorting in now only 20% faster – a 23X decline.
• Filtering is now only 20% faster – a 25X decline.
• Grouping is now 15% slower.
Stream API in Enterprise Java - Problems
8CONFIDENTIAL
Parallel Streams can actually slow you down
• https://github.com/takipi/java-8-parallelism-benchmarks
• http://blog.takipi.com/new-parallelism-apis-in-java-8-behind-the-glitz-and-glamour/
• Diagnosis
• Parallelism with all its benefits also brings in additional types of problems to consider.
• When already acting in a multi-threaded environment, keep this in mind and get yourself
familiar with what’s going on behind the scenes.
Stream API in Enterprise Java - Problems
9CONFIDENTIAL
The flip-side of Lambda expressions - 1
• http://blog.takipi.com/the-dark-side-of-lambda-expressions-in-java-8/
• Let’s say I rise up in the morning and want to iterate over a list of world cup teams and map
their lengths:
• List<Boolean> lengths = new ArrayList<>();
for (String country : Arrays.asList(args)) {
lengths.add(check(country));
}
• Now let’s get functional with a nice lambda:
• Stream lengths = countries.stream().map(countries -> check(country));
• …and what if check method throws an Exception?
Stream API in Enterprise Java - Problems
10CONFIDENTIAL
The flip-side of Lambda expressions - 1
• In that case:
• List<Boolean> lengths = new ArrayList<>();
for (String country : Arrays.asList(args)) {
lengths.add(check(country));
}
• , we`ve got:
• at LmbdaMain.check(LmbdaMain.java:19)
at LmbdaMain.main(LmbdaMain.java:34)
Stream API in Enterprise Java - Problems
11CONFIDENTIAL
The flip-side of Lambda expressions - 1
• In that case:
• Stream lengths = countries.stream().map(countries -> check(country));
• , we`ve got:
• at LmbdaMain.check(LmbdaMain.java:19)
at LmbdaMain.lambda$0(LmbdaMain.java:37)
at LmbdaMain$$Lambda$1/821270929.apply(Unknown Source)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.LongPipeline.reduce(LongPipeline.java:438)
at java.util.stream.LongPipeline.sum(LongPipeline.java:396)
at java.util.stream.ReferencePipeline.count(ReferencePipeline.java:526)
at LmbdaMain.main(LmbdaMain.java:39)
Stream API in Enterprise Java - Problems
12CONFIDENTIAL
The flip-side of Lambda expressions - 1
• In that case:
• ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
String js = "var map = Array.prototype.map n";
• js += "var a = map.call(names, function(name) { return
Java.type("LmbdaMain").check(name) }) n";
js += "print(a)";
engine.eval(js);
Stream API in Enterprise Java - Problems
13CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (1):
• LmbdaMain [Java Application]
• LmbdaMain at localhost:51287
• Thread [main] (Suspended (breakpoint at line 16 in LmbdaMain))
• LmbdaMain.wrap(String) line: 16
• 1525037790.invokeStatic_L_I(Object, Object) line: not available
• 1150538133.invokeSpecial_LL_I(Object, Object, Object) line: not available
• 538592647.invoke_LL_I(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 2150540.interpret_I(MethodHandle, Object, Object) line: not available
• 538592647.invoke_LL_I(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 92150540.interpret_I(MethodHandle, Object, Object) line: not available
• 38592647.invoke_LL_I(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
Stream API in Enterprise Java - Problems
14CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (2):
• LambdaForm.interpretWithArguments(Object...) line: 604
• 731260860.interpret_L(MethodHandle, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LL_L(MethodHandle, Object[]) line: 1108
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available
• 1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available
• 1353530305.linkToCallSite(Object, Object, Object, Object) line: not available
• Script$^eval_._L3(ScriptFunction, Object, Object) line: 3
• 1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available
• 1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
Stream API in Enterprise Java - Problems
15CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (3):
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available
• 93508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available
• 1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available
• 293508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available
• 1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
Stream API in Enterprise Java - Problems
16CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (4):
• 1840903588.interpret_L(MethodHandle, Object, Object, Object, Object, long, Object) line: not available
• 2063763486.reinvoke(Object, Object, Object, Object, Object, long, Object) line: not available
• 850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 82496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available
• 220309324.invokeExact_MT(Object, Object, Object, Object, long, Object, Object) line: not available
• NativeArray$10.forEach(Object, long) line: 1304
• NativeArray$10(IteratorAction).apply() line: 124
• NativeArray.map(Object, Object, Object) line: 1315
• 1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available
• 504858437.invokeExact_MT(Object, Object, Object, Object, Object) line: not available
• FinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 522
• ScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207
• ScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378
• NativeFunction.call(Object, Object...) line: 161
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• 1740189450.invokeSpecial_LLL_L(Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
Stream API in Enterprise Java - Problems
17CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (5):
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available
• 263793464.invokeSpecial_LLLLL_L(Object, Object, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
Stream API in Enterprise Java - Problems
18CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (6):
• 1484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available
• 587003819.invokeSpecial_LLLLLL_L(Object, Object, Object, Object, Object, Object, Object) line: not available
• 811301908.invoke_LLLLLL_L(MethodHandle, Object[]) line: not available
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147
• LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625
• LambdaForm.interpretWithArguments(Object...) line: 604
• 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available
• 2129144075.linkToCallSite(Object, Object, Object, Object, Object) line: not available
• Script$^eval_.runScript(ScriptFunction, Object) line: 3
• 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available
• 1709804316.invokeExact_MT(Object, Object, Object, Object) line: not available
• FinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 498
• ScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207
• ScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378
• NashornScriptEngine.evalImpl(ScriptFunction, ScriptContext, ScriptObject) line: 544
Stream API in Enterprise Java - Problems
19CONFIDENTIAL
The flip-side of Lambda expressions - 1
• , we`ve got (7):
• NashornScriptEngine.evalImpl(ScriptFunction, ScriptContext) line: 526
• NashornScriptEngine.evalImpl(Source, ScriptContext) line: 522
• NashornScriptEngine.eval(String, ScriptContext) line: 193
• NashornScriptEngine(AbstractScriptEngine).eval(String) line: 264
• LmbdaMain.main(String[]) line: 44
Stream API in Enterprise Java - Problems
20CONFIDENTIAL
The flip-side of Lambda expressions - 1
• Diagnosis
• Just stay aware of this, the traces might be a pain from time to time, but it will not keep us
away from them precious lambdas.
Stream API in Enterprise Java - Problems
21CONFIDENTIAL
The flip-side of Lambda expressions – 2
• Overloading gets even worse:
• static <T> T run(Callable<T> c) throws Exception {
return c.call();
}
static <T> T run(Supplier<T> s) throws Exception {
return s.get();
}
• So, we can`t call one of it this way:
• public static void main(String[] args)
throws Exception {
run(() -> null);
// ^^^^^^^^^^ ambiguous method call!
}
• (so, it`s the «static import» and method-pointer`s problem too!)
Stream API in Enterprise Java - Problems
22CONFIDENTIAL
The flip-side of Lambda expressions – 3
• http://blog.jooq.org/2014/04/04/java-8-friday-the-dark-side-of-java-8/
• Not all keywords are supported on default methods:
• They cannot be made final (so, static final too)
• They cannot be made synchronized
• The default keyword:
// Interfaces are always abstract
public /* abstract */ interface NoTrait {
// Abstract methods have no bodies - the abstract keyword is optional
/* abstract */ void run1();
// Concrete methods have bodies - the default keyword is mandatory
default void run2() {}
}
// Classes can optionally be abstract
public abstract class NoInterface {
// Abstract methods have no bodies - the abstract keyword is mandatory
abstract void run1();
// Concrete methods have bodies - the default keyword mustn't be used
void run2() {}
}
Stream API in Enterprise Java - Problems
23CONFIDENTIAL
Default Methods are distracting
http://zeroturnaround.com/rebellabs/how-your-addiction-to-java-8-default-
methods-may-make-pandas-sad-and-your-teammates-angry/
public interface TimeClient {
// ...
static ZoneId getZoneId (String zoneString) {
try {
return ZoneId.of(zoneString);
} catch (DateTimeException e) {
System.err.println("Invalid time zone: " + zoneString + "; using default time zone instead.");
return ZoneId.systemDefault();
}
}
default ZonedDateTime getZonedDateTime(String zoneString) {
return ZonedDateTime.of(getLocalDateTime(), getZoneId(zoneString));
}
}
Diagnosis:
When you hold a hammer everything looks like a nail, keep in mind to stick to their original use case, evolution of
an existing interface when a refactor to introduce a new abstract class doesn’t make sense.
Stream API in Enterprise Java - Problems
24CONFIDENTIAL
Checked Exceptions
• lambda expressions can't declare its throws-clause and lambda body can't throw checked exception
such as IOException
Stream API in Enterprise Java - Problems
25CONFIDENTIAL
Checked Exceptions
• lambda expressions can't declare its throws-clause and lambda body can't throw checked exception
such as IOException
• What if we want to make code like this compile:
• public List<Class> getClasses() throws ClassNotFoundException {
return Stream.of("java.lang.Object", "java.lang.Integer", "java.lang.String")
.map(className -> Class.forName(className))
.collect(Collectors.toList());
}
• This code does not compile, since the Class.forName() method above throws
ClassNotFoundException, which is checked.
Stream API in Enterprise Java - Problems
26CONFIDENTIAL
Checked Exceptions
• Real case:
• public List<Class> getClasses() throws ClassNotFoundException {
return Stream.of("java.lang.Object", "java.lang.Integer", "java.lang.String")
.map(className -> {
try {
return Class.forName(className);
} catch (ClassNotFoundException e)
return null;}})
.filter(aClass -> aClass != null)
.collect(Collectors.toList());
}
Stream API in Enterprise Java - Problems
27CONFIDENTIAL
Field Access
• class Person {
public String name;
public String getName() { return name; }
}
• If we can write this code:
• List<Person> persons;
persons.stream().map(Person::getName).collect(Collectors.toList());
persons.stream().map(p -> p.name).collect(Collectors.toList());
• Why can`t we write something like this?
• persons.stream().map(Person::name).collect(Collectors.toList());
Stream API in Enterprise Java - Problems
28CONFIDENTIAL
Stream API support
• Not present for:
• XPath,
• Serialization (Java, XML, JSON, others),
• Messaging (RebbitMQ, ZeroMQ, Kafka),
• NIO2
• JDBC and JPA
• etc.
Stream API in Enterprise Java - Problems
29CONFIDENTIAL
CriptoPro`blem…
• КриптоПро JCP функционирует в следующем окружении:
• виртуальной машина, удовлетворяющая спецификации Sun Java 2 ™ Virtual Machine;
• требуется Java 2 Runtime Environment версии 1.4.2, 1.5.0 для версии JCP 1.0.46,
Java 6 и выше для 1.0.54 (для этой версии - Java до 1.7.0_25) и 2.x;
Stream API in Enterprise Java - Problems
30CONFIDENTIAL
CriptoPro`blem…
• КриптоПро JCP функционирует в следующем окружении:
• виртуальной машина, удовлетворяющая спецификации Sun Java 2 ™ Virtual Machine;
• требуется Java 2 Runtime Environment версии 1.4.2, 1.5.0 для версии JCP 1.0.46,
Java 6 и выше для 1.0.54 (для этой версии - Java до 1.7.0_25) и 2.x;
Stream API in Enterprise Java - Problems
31CONFIDENTIAL
NIO-2 WatchService
Path path = Paths.get("C:TempUsers");
try (WatchService watchService = FileSystems.getDefault().newWatchService()) {
WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE,
NTRY_MODIFY);
while (true)
try {
System.out.print("Wating for event... ");
for (WatchEvent<?> event : watchService.take().pollEvents())
System.out.println(new Date().toString() + " " + event.kind() + " " +
event.context());
watchKey.reset();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
Stream API in Enterprise Java - Problems
32CONFIDENTIAL
NIO-2 WatchService
Printed:
Wating for event... Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 1.txt
Wating for event... Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 1.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 2.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 2.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 3.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 3.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 4.txt
Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 4.txt
Wating for event... Wed Jun 25 21:06:24 MSK 2014 ENTRY_MODIFY 2.txt
Wating for event... Wed Jun 25 21:06:24 MSK 2014 ENTRY_MODIFY 2.txt
Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt
Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt
Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt
Wating for event...
Stream API in Enterprise Java - Problems
33CONFIDENTIAL
NIO-2 WatchService
Stream API in Enterprise Java - Problems
34CONFIDENTIAL
Generics in ENUM`s
• public enum XPathFilter<T> {
LINKS_FILTER<String>("//div[@class='reports_file']/a", x -> ((XdmItem) x).getStringValue()),
ADJACENT_FILTER<Integer>("...", x -> {/*...*/} );
private String xPath;
private Function<XdmValue, T> function;
XPathFilter(String xPath, Function<XdmValue, T> function) {
this.xPath = xPath;
this.function = function;
}
}
Stream API in Enterprise Java - Problems
35CONFIDENTIAL
Thank you!
Questions?
VYACHESLAV LAPIN

More Related Content

What's hot

The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Shooting the Rapids: Getting the Best from Java 8 Streams
Shooting the Rapids: Getting the Best from Java 8 StreamsShooting the Rapids: Getting the Best from Java 8 Streams
Shooting the Rapids: Getting the Best from Java 8 StreamsMaurice Naftalin
 
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageParallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageMaurice Naftalin
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayYardena Meymann
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Konrad Malawski
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemKonrad Malawski
 
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixEasy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixelliando dias
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Lightbend
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Reactivesummit
 
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...Maurice Naftalin
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Journey's End – Collection and Reduction in the Stream API
Journey's End – Collection and Reduction in the Stream APIJourney's End – Collection and Reduction in the Stream API
Journey's End – Collection and Reduction in the Stream APIMaurice Naftalin
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideMatthew McCullough
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applicationsKnoldus Inc.
 

What's hot (20)

The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Shooting the Rapids: Getting the Best from Java 8 Streams
Shooting the Rapids: Getting the Best from Java 8 StreamsShooting the Rapids: Getting the Best from Java 8 Streams
Shooting the Rapids: Getting the Best from Java 8 Streams
 
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative LanguageParallel-Ready Java Code: Managing Mutation in an Imperative Language
Parallel-Ready Java Code: Managing Mutation in an Imperative Language
 
Shooting the Rapids
Shooting the RapidsShooting the Rapids
Shooting the Rapids
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
 
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMixEasy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
 
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...
Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Pe...
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Journey's End – Collection and Reduction in the Stream API
Journey's End – Collection and Reduction in the Stream APIJourney's End – Collection and Reduction in the Stream API
Journey's End – Collection and Reduction in the Stream API
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 

Viewers also liked

Introduktion om entreprenörskap
Introduktion om entreprenörskapIntroduktion om entreprenörskap
Introduktion om entreprenörskapDaniel Nordström
 
Functional reactive full stack development in java/js (JPoint ed.)
Functional reactive full stack development in java/js (JPoint ed.)Functional reactive full stack development in java/js (JPoint ed.)
Functional reactive full stack development in java/js (JPoint ed.)Vyacheslav Lapin
 
Process journal
Process journalProcess journal
Process journaldiena996
 
Master thesis (pre-Bologna period)
Master thesis (pre-Bologna period)Master thesis (pre-Bologna period)
Master thesis (pre-Bologna period)Josep Maria Grosso
 
Hip hop honeys ws jack
Hip hop honeys ws jackHip hop honeys ws jack
Hip hop honeys ws jackJack Whitaker
 
Ict Introduction and investigation
Ict Introduction and investigationIct Introduction and investigation
Ict Introduction and investigationdiena996
 
Diamond sunum
Diamond sunumDiamond sunum
Diamond sunumakifu46
 
The art of messaging tune (Joker 2015 edition)
The art of messaging tune (Joker 2015 edition)The art of messaging tune (Joker 2015 edition)
The art of messaging tune (Joker 2015 edition)Vyacheslav Lapin
 
Kursintroduktion entreprenörskap
Kursintroduktion entreprenörskapKursintroduktion entreprenörskap
Kursintroduktion entreprenörskapDaniel Nordström
 
Core value management
Core value managementCore value management
Core value managementykim211
 

Viewers also liked (12)

Introduktion om entreprenörskap
Introduktion om entreprenörskapIntroduktion om entreprenörskap
Introduktion om entreprenörskap
 
Functional reactive full stack development in java/js (JPoint ed.)
Functional reactive full stack development in java/js (JPoint ed.)Functional reactive full stack development in java/js (JPoint ed.)
Functional reactive full stack development in java/js (JPoint ed.)
 
Adelaide removalist
Adelaide removalistAdelaide removalist
Adelaide removalist
 
Process journal
Process journalProcess journal
Process journal
 
Master thesis (pre-Bologna period)
Master thesis (pre-Bologna period)Master thesis (pre-Bologna period)
Master thesis (pre-Bologna period)
 
Hip hop honeys ws jack
Hip hop honeys ws jackHip hop honeys ws jack
Hip hop honeys ws jack
 
Ict Introduction and investigation
Ict Introduction and investigationIct Introduction and investigation
Ict Introduction and investigation
 
Diamond sunum
Diamond sunumDiamond sunum
Diamond sunum
 
Intorduktion privatjuridik
Intorduktion privatjuridikIntorduktion privatjuridik
Intorduktion privatjuridik
 
The art of messaging tune (Joker 2015 edition)
The art of messaging tune (Joker 2015 edition)The art of messaging tune (Joker 2015 edition)
The art of messaging tune (Joker 2015 edition)
 
Kursintroduktion entreprenörskap
Kursintroduktion entreprenörskapKursintroduktion entreprenörskap
Kursintroduktion entreprenörskap
 
Core value management
Core value managementCore value management
Core value management
 

Similar to ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функционального программирования для вашего enterprise java-проекта

Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLMorgan Dedmon
 
How to debug slow lambda response times
How to debug slow lambda response timesHow to debug slow lambda response times
How to debug slow lambda response timesYan Cui
 
GraphQL-PHP: Dos and don'ts
GraphQL-PHP: Dos and don'tsGraphQL-PHP: Dos and don'ts
GraphQL-PHP: Dos and don'tsVáclav Šír
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and SprayNexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and SprayMatthew Farwell
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopEventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopAyon Sinha
 
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...HostedbyConfluent
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleJulian Gamble
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in ScalaAlex Payne
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Flink Forward
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeksjutley
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveXu Jiang
 
AWS Lambda support for AWS X-Ray
AWS Lambda support for AWS X-RayAWS Lambda support for AWS X-Ray
AWS Lambda support for AWS X-RayEitan Sela
 

Similar to ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функционального программирования для вашего enterprise java-проекта (20)

Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
How to debug slow lambda response times
How to debug slow lambda response timesHow to debug slow lambda response times
How to debug slow lambda response times
 
GraphQL-PHP: Dos and don'ts
GraphQL-PHP: Dos and don'tsGraphQL-PHP: Dos and don'ts
GraphQL-PHP: Dos and don'ts
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Javantura v4 - Java and lambdas and streams - are they better than for loops ...
Javantura v4 - Java and lambdas and streams - are they better than for loops ...Javantura v4 - Java and lambdas and streams - are they better than for loops ...
Javantura v4 - Java and lambdas and streams - are they better than for loops ...
 
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and SprayNexthink Library - replacing a ruby on rails application with Scala and Spray
Nexthink Library - replacing a ruby on rails application with Scala and Spray
 
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and HadoopEventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
Eventual Consistency @WalmartLabs with Kafka, Avro, SolrCloud and Hadoop
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
 
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...
Implementing End-To-End Tracing With Roman Kolesnev and Antony Stubbs | Curre...
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
 
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
Virtual Flink Forward 2020: How Streaming Helps Your Staging Environment and ...
 
Java 8
Java 8Java 8
Java 8
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeks
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
 
AWS Lambda support for AWS X-Ray
AWS Lambda support for AWS X-RayAWS Lambda support for AWS X-Ray
AWS Lambda support for AWS X-Ray
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функционального программирования для вашего enterprise java-проекта

  • 1. 1CONFIDENTIAL Senior developer 10+ years experience in IT • 7+ Java-development experience • 5+ trainer experience • 3+ system analysis Interests: • Messaging • Functional programming (Clojure, Scala) About author
  • 2. 2CONFIDENTIAL • Parallel Streams can actually slow you down • The flip-side of Lambda expressions • Default Methods are distracting • Checked Exceptions • Field Access • Stream API support • CriptoPro`blem… • NIO-2 WatchService • Generics in ENUM`s AGENDA
  • 3. 3CONFIDENTIAL Parallel Streams can actually slow you down • Java 8 brings the promise of parallelism as one of the most anticipated new features. The .parallelStream() method implements this on collections and streams. It breaks them into subproblems which then run on separate threads for processing, these can go to different cores and then get combined when they’re done. This all happens under the hood using the fork/join framework. • Ok, sounds cool, it must speed up operations on large data sets in multi-core environments, right? Stream API in Enterprise Java - Problems
  • 4. 4CONFIDENTIAL Parallel Streams can actually slow you down • Let`s test it: • To sort an array using multiple cores all you have to do is – – Arrays.parallelSort(numbers); • To group a collection into different groups based on a specific criteria (e.g. prime and non-prime numbers) – Map<Boolean, List> groupByPrimary = numbers.parallelStream() .collect(Collectors.groupingBy(s -> Utility.isPrime(s))); • 3 . To filter out values all you have do is – – Integer[] prims = numbers.parallelStream().filter(s -> Utility.isPrime(s)) .toArray(); Stream API in Enterprise Java - Problems
  • 5. 5CONFIDENTIAL Parallel Streams can actually slow you down • https://github.com/takipi/java-8-parallelism-benchmarks Stream API in Enterprise Java - Problems
  • 6. 6CONFIDENTIAL Parallel Streams can actually slow you down • The results were not surprising: • Quicksort is now 4.7X times faster. • Grouping is now 5X times faster. • Filtering is now 5.5X times faster. • A happy ending? Unfortunately not. • So what happens under load? • So far things have been quite peachy, the reason being that there’s little contention between threads for CPU cycles. That’s an ideal situation, but unfortunately, one that doesn’t happen a lot in real life. To simulate a scenario which is more on par with what you’d normally see in a real-world environment I set up a second test. This test runs the same set of algorithms, but this time executes them on ten concurrent threads to simulate processing ten concurrent requests performed by a server when it’s under pressure. Each of those requests will then be handled either sequentially using a traditional approach, or the new Java 8 APIs. Stream API in Enterprise Java - Problems
  • 7. 7CONFIDENTIAL Parallel Streams can actually slow you down • The results: • Sorting in now only 20% faster – a 23X decline. • Filtering is now only 20% faster – a 25X decline. • Grouping is now 15% slower. Stream API in Enterprise Java - Problems
  • 8. 8CONFIDENTIAL Parallel Streams can actually slow you down • https://github.com/takipi/java-8-parallelism-benchmarks • http://blog.takipi.com/new-parallelism-apis-in-java-8-behind-the-glitz-and-glamour/ • Diagnosis • Parallelism with all its benefits also brings in additional types of problems to consider. • When already acting in a multi-threaded environment, keep this in mind and get yourself familiar with what’s going on behind the scenes. Stream API in Enterprise Java - Problems
  • 9. 9CONFIDENTIAL The flip-side of Lambda expressions - 1 • http://blog.takipi.com/the-dark-side-of-lambda-expressions-in-java-8/ • Let’s say I rise up in the morning and want to iterate over a list of world cup teams and map their lengths: • List<Boolean> lengths = new ArrayList<>(); for (String country : Arrays.asList(args)) { lengths.add(check(country)); } • Now let’s get functional with a nice lambda: • Stream lengths = countries.stream().map(countries -> check(country)); • …and what if check method throws an Exception? Stream API in Enterprise Java - Problems
  • 10. 10CONFIDENTIAL The flip-side of Lambda expressions - 1 • In that case: • List<Boolean> lengths = new ArrayList<>(); for (String country : Arrays.asList(args)) { lengths.add(check(country)); } • , we`ve got: • at LmbdaMain.check(LmbdaMain.java:19) at LmbdaMain.main(LmbdaMain.java:34) Stream API in Enterprise Java - Problems
  • 11. 11CONFIDENTIAL The flip-side of Lambda expressions - 1 • In that case: • Stream lengths = countries.stream().map(countries -> check(country)); • , we`ve got: • at LmbdaMain.check(LmbdaMain.java:19) at LmbdaMain.lambda$0(LmbdaMain.java:37) at LmbdaMain$$Lambda$1/821270929.apply(Unknown Source) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.LongPipeline.reduce(LongPipeline.java:438) at java.util.stream.LongPipeline.sum(LongPipeline.java:396) at java.util.stream.ReferencePipeline.count(ReferencePipeline.java:526) at LmbdaMain.main(LmbdaMain.java:39) Stream API in Enterprise Java - Problems
  • 12. 12CONFIDENTIAL The flip-side of Lambda expressions - 1 • In that case: • ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); String js = "var map = Array.prototype.map n"; • js += "var a = map.call(names, function(name) { return Java.type("LmbdaMain").check(name) }) n"; js += "print(a)"; engine.eval(js); Stream API in Enterprise Java - Problems
  • 13. 13CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (1): • LmbdaMain [Java Application] • LmbdaMain at localhost:51287 • Thread [main] (Suspended (breakpoint at line 16 in LmbdaMain)) • LmbdaMain.wrap(String) line: 16 • 1525037790.invokeStatic_L_I(Object, Object) line: not available • 1150538133.invokeSpecial_LL_I(Object, Object, Object) line: not available • 538592647.invoke_LL_I(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 2150540.interpret_I(MethodHandle, Object, Object) line: not available • 538592647.invoke_LL_I(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 92150540.interpret_I(MethodHandle, Object, Object) line: not available • 38592647.invoke_LL_I(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 Stream API in Enterprise Java - Problems
  • 14. 14CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (2): • LambdaForm.interpretWithArguments(Object...) line: 604 • 731260860.interpret_L(MethodHandle, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LL_L(MethodHandle, Object[]) line: 1108 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available • 1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available • 1353530305.linkToCallSite(Object, Object, Object, Object) line: not available • Script$^eval_._L3(ScriptFunction, Object, Object) line: 3 • 1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available • 1597655940.invokeSpecial_LLLL_L(Object, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 Stream API in Enterprise Java - Problems
  • 15. 15CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (3): • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available • 93508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available • 1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 282496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available • 293508253.invokeSpecial_LLLLJL_L(Object, Object, Object, Object, Object, long, Object) line: not available • 1850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 Stream API in Enterprise Java - Problems
  • 16. 16CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (4): • 1840903588.interpret_L(MethodHandle, Object, Object, Object, Object, long, Object) line: not available • 2063763486.reinvoke(Object, Object, Object, Object, Object, long, Object) line: not available • 850777594.invoke_LLLLJL_L(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 82496973.interpret_L(MethodHandle, Object, Object, Object, long, Object) line: not available • 220309324.invokeExact_MT(Object, Object, Object, Object, long, Object, Object) line: not available • NativeArray$10.forEach(Object, long) line: 1304 • NativeArray$10(IteratorAction).apply() line: 124 • NativeArray.map(Object, Object, Object) line: 1315 • 1596000437.invokeStatic_LLL_L(Object, Object, Object, Object) line: not available • 504858437.invokeExact_MT(Object, Object, Object, Object, Object) line: not available • FinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 522 • ScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207 • ScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378 • NativeFunction.call(Object, Object...) line: 161 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • 1740189450.invokeSpecial_LLL_L(Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available Stream API in Enterprise Java - Problems
  • 17. 17CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (5): • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 2619171.interpret_L(MethodHandle, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLL_L(MethodHandle, Object[]) line: 1113 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLL_L(MethodHandle, Object[]) line: 1118 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available • 263793464.invokeSpecial_LLLLL_L(Object, Object, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 Stream API in Enterprise Java - Problems
  • 18. 18CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (6): • 1484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available • 587003819.invokeSpecial_LLLLLL_L(Object, Object, Object, Object, Object, Object, Object) line: not available • 811301908.invoke_LLLLLL_L(MethodHandle, Object[]) line: not available • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 484673893.interpret_L(MethodHandle, Object, Object, Object, Object, Object) line: not available • LambdaForm$NamedFunction.invoke_LLLLL_L(MethodHandle, Object[]) line: 1123 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • LambdaForm$NamedFunction.invokeWithArguments(Object...) line: 1147 • LambdaForm.interpretName(LambdaForm$Name, Object[]) line: 625 • LambdaForm.interpretWithArguments(Object...) line: 604 • 323326911.interpret_L(MethodHandle, Object, Object, Object, Object) line: not available • 2129144075.linkToCallSite(Object, Object, Object, Object, Object) line: not available • Script$^eval_.runScript(ScriptFunction, Object) line: 3 • 1076496284.invokeStatic_LL_L(Object, Object, Object) line: not available • 1709804316.invokeExact_MT(Object, Object, Object, Object) line: not available • FinalScriptFunctionData(ScriptFunctionData).invoke(ScriptFunction, Object, Object...) line: 498 • ScriptFunctionImpl(ScriptFunction).invoke(Object, Object...) line: 207 • ScriptRuntime.apply(ScriptFunction, Object, Object...) line: 378 • NashornScriptEngine.evalImpl(ScriptFunction, ScriptContext, ScriptObject) line: 544 Stream API in Enterprise Java - Problems
  • 19. 19CONFIDENTIAL The flip-side of Lambda expressions - 1 • , we`ve got (7): • NashornScriptEngine.evalImpl(ScriptFunction, ScriptContext) line: 526 • NashornScriptEngine.evalImpl(Source, ScriptContext) line: 522 • NashornScriptEngine.eval(String, ScriptContext) line: 193 • NashornScriptEngine(AbstractScriptEngine).eval(String) line: 264 • LmbdaMain.main(String[]) line: 44 Stream API in Enterprise Java - Problems
  • 20. 20CONFIDENTIAL The flip-side of Lambda expressions - 1 • Diagnosis • Just stay aware of this, the traces might be a pain from time to time, but it will not keep us away from them precious lambdas. Stream API in Enterprise Java - Problems
  • 21. 21CONFIDENTIAL The flip-side of Lambda expressions – 2 • Overloading gets even worse: • static <T> T run(Callable<T> c) throws Exception { return c.call(); } static <T> T run(Supplier<T> s) throws Exception { return s.get(); } • So, we can`t call one of it this way: • public static void main(String[] args) throws Exception { run(() -> null); // ^^^^^^^^^^ ambiguous method call! } • (so, it`s the «static import» and method-pointer`s problem too!) Stream API in Enterprise Java - Problems
  • 22. 22CONFIDENTIAL The flip-side of Lambda expressions – 3 • http://blog.jooq.org/2014/04/04/java-8-friday-the-dark-side-of-java-8/ • Not all keywords are supported on default methods: • They cannot be made final (so, static final too) • They cannot be made synchronized • The default keyword: // Interfaces are always abstract public /* abstract */ interface NoTrait { // Abstract methods have no bodies - the abstract keyword is optional /* abstract */ void run1(); // Concrete methods have bodies - the default keyword is mandatory default void run2() {} } // Classes can optionally be abstract public abstract class NoInterface { // Abstract methods have no bodies - the abstract keyword is mandatory abstract void run1(); // Concrete methods have bodies - the default keyword mustn't be used void run2() {} } Stream API in Enterprise Java - Problems
  • 23. 23CONFIDENTIAL Default Methods are distracting http://zeroturnaround.com/rebellabs/how-your-addiction-to-java-8-default- methods-may-make-pandas-sad-and-your-teammates-angry/ public interface TimeClient { // ... static ZoneId getZoneId (String zoneString) { try { return ZoneId.of(zoneString); } catch (DateTimeException e) { System.err.println("Invalid time zone: " + zoneString + "; using default time zone instead."); return ZoneId.systemDefault(); } } default ZonedDateTime getZonedDateTime(String zoneString) { return ZonedDateTime.of(getLocalDateTime(), getZoneId(zoneString)); } } Diagnosis: When you hold a hammer everything looks like a nail, keep in mind to stick to their original use case, evolution of an existing interface when a refactor to introduce a new abstract class doesn’t make sense. Stream API in Enterprise Java - Problems
  • 24. 24CONFIDENTIAL Checked Exceptions • lambda expressions can't declare its throws-clause and lambda body can't throw checked exception such as IOException Stream API in Enterprise Java - Problems
  • 25. 25CONFIDENTIAL Checked Exceptions • lambda expressions can't declare its throws-clause and lambda body can't throw checked exception such as IOException • What if we want to make code like this compile: • public List<Class> getClasses() throws ClassNotFoundException { return Stream.of("java.lang.Object", "java.lang.Integer", "java.lang.String") .map(className -> Class.forName(className)) .collect(Collectors.toList()); } • This code does not compile, since the Class.forName() method above throws ClassNotFoundException, which is checked. Stream API in Enterprise Java - Problems
  • 26. 26CONFIDENTIAL Checked Exceptions • Real case: • public List<Class> getClasses() throws ClassNotFoundException { return Stream.of("java.lang.Object", "java.lang.Integer", "java.lang.String") .map(className -> { try { return Class.forName(className); } catch (ClassNotFoundException e) return null;}}) .filter(aClass -> aClass != null) .collect(Collectors.toList()); } Stream API in Enterprise Java - Problems
  • 27. 27CONFIDENTIAL Field Access • class Person { public String name; public String getName() { return name; } } • If we can write this code: • List<Person> persons; persons.stream().map(Person::getName).collect(Collectors.toList()); persons.stream().map(p -> p.name).collect(Collectors.toList()); • Why can`t we write something like this? • persons.stream().map(Person::name).collect(Collectors.toList()); Stream API in Enterprise Java - Problems
  • 28. 28CONFIDENTIAL Stream API support • Not present for: • XPath, • Serialization (Java, XML, JSON, others), • Messaging (RebbitMQ, ZeroMQ, Kafka), • NIO2 • JDBC and JPA • etc. Stream API in Enterprise Java - Problems
  • 29. 29CONFIDENTIAL CriptoPro`blem… • КриптоПро JCP функционирует в следующем окружении: • виртуальной машина, удовлетворяющая спецификации Sun Java 2 ™ Virtual Machine; • требуется Java 2 Runtime Environment версии 1.4.2, 1.5.0 для версии JCP 1.0.46, Java 6 и выше для 1.0.54 (для этой версии - Java до 1.7.0_25) и 2.x; Stream API in Enterprise Java - Problems
  • 30. 30CONFIDENTIAL CriptoPro`blem… • КриптоПро JCP функционирует в следующем окружении: • виртуальной машина, удовлетворяющая спецификации Sun Java 2 ™ Virtual Machine; • требуется Java 2 Runtime Environment версии 1.4.2, 1.5.0 для версии JCP 1.0.46, Java 6 и выше для 1.0.54 (для этой версии - Java до 1.7.0_25) и 2.x; Stream API in Enterprise Java - Problems
  • 31. 31CONFIDENTIAL NIO-2 WatchService Path path = Paths.get("C:TempUsers"); try (WatchService watchService = FileSystems.getDefault().newWatchService()) { WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, NTRY_MODIFY); while (true) try { System.out.print("Wating for event... "); for (WatchEvent<?> event : watchService.take().pollEvents()) System.out.println(new Date().toString() + " " + event.kind() + " " + event.context()); watchKey.reset(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } Stream API in Enterprise Java - Problems
  • 32. 32CONFIDENTIAL NIO-2 WatchService Printed: Wating for event... Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 1.txt Wating for event... Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 1.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 2.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 2.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 3.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 3.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_CREATE 4.txt Wed Jun 25 21:05:38 MSK 2014 ENTRY_MODIFY 4.txt Wating for event... Wed Jun 25 21:06:24 MSK 2014 ENTRY_MODIFY 2.txt Wating for event... Wed Jun 25 21:06:24 MSK 2014 ENTRY_MODIFY 2.txt Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt Wating for event... Wed Jun 25 21:08:53 MSK 2014 ENTRY_MODIFY 3.txt Wating for event... Stream API in Enterprise Java - Problems
  • 33. 33CONFIDENTIAL NIO-2 WatchService Stream API in Enterprise Java - Problems
  • 34. 34CONFIDENTIAL Generics in ENUM`s • public enum XPathFilter<T> { LINKS_FILTER<String>("//div[@class='reports_file']/a", x -> ((XdmItem) x).getStringValue()), ADJACENT_FILTER<Integer>("...", x -> {/*...*/} ); private String xPath; private Function<XdmValue, T> function; XPathFilter(String xPath, Function<XdmValue, T> function) { this.xPath = xPath; this.function = function; } } Stream API in Enterprise Java - Problems