devday2012
-
Upload
juan-lopes -
Category
Technology
-
view
966 -
download
0
description
Transcript of devday2012
JAVAPARA PROGRAMADORES .NET
@juanplopes
Rio de Janeiro
Bel' Zonte
Em comunidades,pessoas antes de tecnologias.
REVELAÇÃO!
REVELAÇÃO!
https://github.com/juanplopes/mublasters
VAMOS FALAR MAL DE
SISTEMA DE TIPOS NÃO É UNIFICADO
NÃO TEM STRUCTS
GENERICS TEM TYPE ERASURE
API DE DATAS SOFRÍVEL
NÃO TEM ITERATOR METHODS
NÃO TEM CLOSURES OU LAMBDAS
java.util.concurrent
NÃO CRIE THREADS
new Thread(new Runnable() { public void run() {
}}).start();
TRABALHANDO COM FUTURES
Future é a promessa do resultado de uma computação que ainda não terminou (ou sequer começou).
TRABALHANDO COM FUTURES
ExecutorService executor = ...
Future future = executor.submit(new Runnable() { public void run() {
}});
//qualquer outro trabalho
future.get(); //bloqueante
TRABALHANDO COM FUTURES
ExecutorService executor = ...
Future<String> future = executor.submit(new Callable<String>() { public String call() {
return "42"; }});
//qualquer outro trabalho
String result = future.get(); //bloqueante
.NET TASK FACTORY
TaskFactory factory = ...
var task = factory.StartNew(() => "42");
//qualquer outro trabalho
String result = future.Result; //bloqueante
.NET TASK FACTORY
Java 5 (2004)ExecutorService e Future<T>
.NET 4 (2010)TaskFactory, TaskScheduler e
Task<T>
TRABALHANDO COM FUTURES
ExecutorsnewCachedThreadPool()newFixedThreadPool(n)newScheduledThreadPool(n)newSingleThreadExecutor()
guava.MoreExecutorssameThreadExecutor()listeningDecorator(executor)
E A SINCRONIZAÇÃO?
COLEÇÕES CONCORRENTES
ConcurrentMap<T, K>
putIfAbsent(key, value)remove(key, value)replace(key, value)replace(key, oldValue, newValue)
ConcurrentNavigableMap<T, K>
headMap(toKey)tailMap(fromKey)subMap(fromKey, toKey)
COLEÇÕES CONCORRENTES
PROBLEMA DO PRODUTOR-CONSUMIDOR
A BBUFFER
produz consome
COLEÇÕES BLOQUEANTES
ArrayBlockingQueue<T>,PriorityBlockingQueue<T>DelayQueue<T>
Exception: add, removeRetorna Flag: offer, pollBloqueia: put, takeTimeout: offer², poll²
ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO
Semaphore
acquire(number)release(number)
ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO
CountDownLatch
countDown()await()
ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO
CyclicBarrier
await()
OPEN SOURCE
APACHE
HadoopLuceneMavenTomcatZooKeeperHBaseSolrActiveMQAntLog4J
RED HAT
HibernateJBossTorqueBoxJGroupsInfinispanAeroGearDroolsEJB3HornetQRichFaces
GuavaGuice ('Juice')GsonProtocol BuffersContractsGWTCaliper
OPEN JDK
APACHE MAVEN
<dependency> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version></dependency>
APACHE MAVEN
JGROUPS
JChannel channel = new JChannel();channel.setReceiver(new ReceiverAdapter() { public void receive(Message msg) { System.out.println( msg.getSrc() + ": " + msg.getObject()); }});
channel.connect("meuCanalDeChat");
BufferedReader reader = new BufferedReader( new InputStreamReader(System.in));while(true) { String line = reader.readLine(); channel.send(null, line);}
GUAVA
PreconditionsImmutable CollectionsCachingFunctional IdiomsSigned NumbersReflectionMathOptimized Data StructuresSimplified I/O
GUAVA
LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.MINUTES) .removalListener(MY_LISTENER) .build(new CacheLoader<Key, Graph>() { public Graph load(Key key) throws AnyException { return createExpensiveGraph(key); } });
GUICE ou SPRING?
É mais rápidoSem XMLMenos AnnotationsMelhores convençõesAOP embutido
Mais usuáriosNão é só IOC
Integra melhorMais documentação
MOCKITO
when(obj.method()).thenReturn(42);
verify(obj).method();
LINGUAGENS ALTERNATIVAS
● JRuby● Clojure● Scala● Groovy● DynJS
IDE
IDEIDEs
HOTSPOT
JIT E ADAPTIVE OPTIMIZATION
Loop UnrollingMethod inliningExact Type InferenceType Test Strength ReductionDead Code EliminationTiered CompilationLock ElisionDereflectionAutobox Elimination
GC: CONCURRENT MARK SWEEP
JVISUALVM
JVISUALVM
YOURKIT PROFILER
Tecnologia não é religião, time de futebol ou partido
político.
Obrigado.