Skip to content

Instantly share code, notes, and snippets.

@sharrissf
sharrissf / gist:700690
Created November 15, 2010 17:58
Direct Memory vs On Heap in Java
import java.nio.ByteBuffer;
import java.util.Random;
public class BufferPerformanceComparison {
public final static int MEGA_BYTE = 1024 * 1024;
public final static long GIGA_BYTE = MEGA_BYTE * 1024;
private final ByteBuffer heapByteBuffer;
private final ByteBuffer offHeapByteBuffer;
private final long dataToLoad;
private final int bufferSize;
@sharrissf
sharrissf / gist:720867
Created November 29, 2010 23:59
Compare the construction of Quartz jobs between Quartz 1.8.4 and Quartz 2.0
//Quartz 1.8.4 Example 2
// First we must get a reference to a scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
log.info("------- Initialization Complete -----------");
log.info("------- Scheduling Jobs -------------------");
// computer a time that is on the next round minute
@sharrissf
sharrissf / gist:720905
Created November 30, 2010 00:27
Quartz Scheduler Example 2 comparison
//Quartz scheduler Example 2 from 1.8.3
// job3 will run 11 times (run once and repeat 10 more times)
// job3 will repeat every 10 seconds (10000 ms)
job = new JobDetail("job3", "group1", SimpleJob.class);
trigger = new SimpleTrigger("trigger3", "group1", "job3", "group1",
new Date(ts), null, 10, 10000L);
ft = sched.scheduleJob(job, trigger);
// the same job (job3) will be scheduled by a another trigger
@sharrissf
sharrissf / gist:720910
Created November 30, 2010 00:33
Quartz Scheduler Example 3 comparison
//Quartz 1.8.4 Example 3 snippet
// job 7 will run every 30 seconds but only on Weekends (Saturday and
// Sunday)
job = new JobDetail("job7", "group1", SimpleJob.class);
trigger = new CronTrigger("trigger7", "group1", "job7", "group1",
"0,30 * * ? * SAT,SUN");
sched.addJob(job, true);
ft = sched.scheduleJob(trigger);
@sharrissf
sharrissf / gist:769735
Created January 7, 2011 17:01
Terracotta Maven repos
<repositories>
<repository>
<id>terracotta-snapshots</id>
<name>Terracotta Repo</name>
<url>http://www.terracotta.org/download/reflector/releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
@sharrissf
sharrissf / gist:828611
Created February 16, 2011 00:37
Sample of doing a query
Query query = cache.createQuery();
query.includeKeys();
query.includeValues();
query.addCriteria(name.ilike(“Greg*”).and(gender.eq(Gender.MALE))).addOrderBy(age, Direction.ASCENDING).maxResults(10);
Results results = query.execute();
System.out.println(” Size: ” + results.size());
for (Result result : results.all()) {
System.out.println(“Got: Key[" + result.getKey() + "] Value class [" + result.getValue().getClass() + "] Value [" + result.getValue() + "]“);
}
Configuration config;
FactoryConfiguration factoryConfig = new FactoryConfiguration();
factoryConfig.setClass("org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory");
factoryConfig.setProperties("monitorAddress=localhost, monitorPort=9889");
config.addCacheManagerPeerListenerFactory(factoryConfig);
... and in pom.xml:
<dependency>
<groupId>org.terracotta</groupId>
albums = getAllAlbumsBy(artist);
songs = getAllSongs(artist);
printSongCountHeader(songs.size());
pringAlbumCountHeader(albums.size());
public Collection getAllAlbumsBy(Artist artist){
List results = new ArrayList();
for(Iterator i = getAllAlbums();i.hasNext();){
Album album = (Album)i.next();
if(album.isBy(artist)){
results.add(album);
}
}
return results;
@sharrissf
sharrissf / gist:1077193
Created July 12, 2011 01:21
Ehcache Bytes Based Tuning
//Go from this
<ehcache>
// to this
<ehcache maxBytesLocalHeap="100M" >
// or
<ehcache maxBytesLocalHeap="50%" >