devday2012

50
JAVA PARA PROGRAMADORES .NET @juanplopes

Upload: juan-lopes

Post on 09-May-2015

966 views

Category:

Technology


0 download

DESCRIPTION

Palestra sobre Java no DevDay BH 2012

TRANSCRIPT

Page 1: devday2012

JAVAPARA PROGRAMADORES .NET

@juanplopes

Page 2: devday2012

Rio de Janeiro

Page 3: devday2012

Bel' Zonte

Page 4: devday2012

Em comunidades,pessoas antes de tecnologias.

Page 5: devday2012

REVELAÇÃO!

Page 6: devday2012

REVELAÇÃO!

https://github.com/juanplopes/mublasters

Page 7: devday2012
Page 8: devday2012

VAMOS FALAR MAL DE

Page 9: devday2012

SISTEMA DE TIPOS NÃO É UNIFICADO

NÃO TEM STRUCTS

GENERICS TEM TYPE ERASURE

Page 10: devday2012

API DE DATAS SOFRÍVEL

NÃO TEM ITERATOR METHODS

NÃO TEM CLOSURES OU LAMBDAS

Page 11: devday2012
Page 12: devday2012

java.util.concurrent

Page 13: devday2012

NÃO CRIE THREADS

new Thread(new Runnable() { public void run() {

}}).start();

Page 14: devday2012

TRABALHANDO COM FUTURES

Future é a promessa do resultado de uma computação que ainda não terminou (ou sequer começou).

Page 15: devday2012

TRABALHANDO COM FUTURES

ExecutorService executor = ...

Future future = executor.submit(new Runnable() { public void run() {

}});

//qualquer outro trabalho

future.get(); //bloqueante

Page 16: devday2012

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

Page 17: devday2012

.NET TASK FACTORY

TaskFactory factory = ...

var task = factory.StartNew(() => "42");

//qualquer outro trabalho

String result = future.Result; //bloqueante

Page 18: devday2012

.NET TASK FACTORY

Java 5 (2004)ExecutorService e Future<T>

.NET 4 (2010)TaskFactory, TaskScheduler e

Task<T>

Page 19: devday2012

TRABALHANDO COM FUTURES

ExecutorsnewCachedThreadPool()newFixedThreadPool(n)newScheduledThreadPool(n)newSingleThreadExecutor()

guava.MoreExecutorssameThreadExecutor()listeningDecorator(executor)

Page 20: devday2012

E A SINCRONIZAÇÃO?

Page 21: devday2012

COLEÇÕES CONCORRENTES

ConcurrentMap<T, K>

putIfAbsent(key, value)remove(key, value)replace(key, value)replace(key, oldValue, newValue)

Page 22: devday2012

ConcurrentNavigableMap<T, K>

headMap(toKey)tailMap(fromKey)subMap(fromKey, toKey)

COLEÇÕES CONCORRENTES

Page 23: devday2012

PROBLEMA DO PRODUTOR-CONSUMIDOR

A BBUFFER

produz consome

Page 24: devday2012

COLEÇÕES BLOQUEANTES

ArrayBlockingQueue<T>,PriorityBlockingQueue<T>DelayQueue<T>

Exception: add, removeRetorna Flag: offer, pollBloqueia: put, takeTimeout: offer², poll²

Page 25: devday2012

ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO

Semaphore

acquire(number)release(number)

Page 26: devday2012

ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO

CountDownLatch

countDown()await()

Page 27: devday2012

ESTRUTURAS DE DADOS DE SINCRONIZAÇÃO

CyclicBarrier

await()

Page 28: devday2012

OPEN SOURCE

Page 29: devday2012

APACHE

HadoopLuceneMavenTomcatZooKeeperHBaseSolrActiveMQAntLog4J

Page 30: devday2012

RED HAT

HibernateJBossTorqueBoxJGroupsInfinispanAeroGearDroolsEJB3HornetQRichFaces

Page 31: devday2012

GOOGLE

GuavaGuice ('Juice')GsonProtocol BuffersContractsGWTCaliper

Page 32: devday2012

OPEN JDK

Page 33: devday2012

APACHE MAVEN

<dependency> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version></dependency>

Page 34: devday2012

APACHE MAVEN

Page 35: devday2012

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);}

Page 36: devday2012

GUAVA

PreconditionsImmutable CollectionsCachingFunctional IdiomsSigned NumbersReflectionMathOptimized Data StructuresSimplified I/O

Page 37: devday2012

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); } });

Page 38: devday2012

GUICE ou SPRING?

É mais rápidoSem XMLMenos AnnotationsMelhores convençõesAOP embutido

Mais usuáriosNão é só IOC

Integra melhorMais documentação

Page 39: devday2012

MOCKITO

when(obj.method()).thenReturn(42);

verify(obj).method();

Page 40: devday2012

LINGUAGENS ALTERNATIVAS

● JRuby● Clojure● Scala● Groovy● DynJS

Page 41: devday2012

IDE

Page 42: devday2012

IDEIDEs

Page 43: devday2012

HOTSPOT

Page 44: devday2012

JIT E ADAPTIVE OPTIMIZATION

Loop UnrollingMethod inliningExact Type InferenceType Test Strength ReductionDead Code EliminationTiered CompilationLock ElisionDereflectionAutobox Elimination

Page 45: devday2012

GC: CONCURRENT MARK SWEEP

Page 46: devday2012

JVISUALVM

Page 47: devday2012

JVISUALVM

Page 48: devday2012

YOURKIT PROFILER

Page 49: devday2012

Tecnologia não é religião, time de futebol ou partido

político.

Page 50: devday2012

Obrigado.