Uno scrittoio digitale …

23 gennaio 2017

to be seen

Archiviato in: java — Tag: — admin @ 09:41

custom collectors in java
jmh for java
Simple performance framework for java

7 luglio 2016

java mysql driver

Archiviato in: code, java — Tag:, — admin @ 10:10

avoid OutOfMemory with simulated streaming:


            conn = DriverManager.getConnection(ds.getJdbcUrl(), ds.getUser(), ds.getPassword());
            stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
            stmt.setFetchSize(Integer.MIN_VALUE);

16 giugno 2015

Byteman

Archiviato in: code, java — Tag:, , — admin @ 20:59

Byteman is a byte code manipulation and injection tool kit. It allows us to intercept and replace arbitrary parts of Java code to make it behave differently or break it (on purpose):

> get all threads stuck in a certain place and let them continue at the same time (hello race condition)
> throw Exceptions at unexpected locations
> tracing through your code during execution
>change return values

and a lot more things.

21 maggio 2015

MapDB (java library)

Archiviato in: java — Tag:, , , — admin @ 20:24

MapDB is embedded database engine. It provides java collections backed by disk or memory database store. MapDB has excellent performance comparable to java.util.HashMap and other collections, but is not limited by GC. It is also very flexible engine with many storage backend, cache algorithms, and so on. And finally MapDB is pure-java single 400K JAR and only depends on JRE 6+ or Android 2.1+.

What for?
> In-memory cache with expiration based on time-to-live or maximal size, Redis or EZCache replacement
> Huge indexes
> Persistent data model
> Alternative memory model if you are limited by GC

15 gennaio 2015

JPA 2.*

Archiviato in: code, java — admin @ 00:41

Solo qualche link utile … a capirci qualcosa :D

guice and jpa
example
wiki

27 dicembre 2014

jGroups

Archiviato in: java — Tag:, — admin @ 17:25

qua

JGroups is a toolkit for reliable messaging. It can be used to create clusters whose nodes can send messages to each other. The main features include

> Cluster creation and deletion. Cluster nodes can be spread across LANs or WANs
> Joining and leaving of clusters
> Membership detection and notification about joined/left/crashed cluster nodes
> Detection and removal of crashed nodes
> Sending and receiving of node-to-cluster messages (point-to-multipoint)
> Sending and receiving of node-to-node messages (point-to-point)

10 ottobre 2014

Jcabi

Archiviato in: code, java — Tag:, , — admin @ 17:42

hanno sviluppato un casino di progetti … come si può vedere qua

31 marzo 2014

Eclipse Inside Proxy

Archiviato in: code, java — admin @ 21:37

Cosa è … e come si usa si trova QUI

30 gennaio 2014

Java thread dump

Archiviato in: java, sapere è potere — admin @ 23:08

un paio di link da spulciare sul treno …

http://architects.dzone.com/articles/how-analyze-java-thread-dumps
mat
jhat
http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html

L’ultimo citato (jhat) è abbastanza instabile su grossi file … ma fà cmq il suo sporco lavoro
Il top è assolutamente mat (un tool stand-alone costruito sul framework di Eclipse)
La Oracle sponsorizza jmap … ma non ho avuto ancora il tempo di provarlo
Non dimentichiamo in ogni caso VisualVM … l’ho usato parecchio, ma le informazioni sono un pò nascoste

22 settembre 2013

java.util.concurrent.*

Archiviato in: java — admin @ 18:03

ho raccolto un pò di informazioni in un unico pdf (non esaustivo)

30 agosto 2013

Zero-downtime Deployment (and Rollback) in Tomcat

Archiviato in: java, web — admin @ 23:03

deployare due o più versioni della stessa webapp ? … oh yeah (è possibile)
qua

17 luglio 2013

Web Resource Optimizer for Java

Archiviato in: java — Tag:, , , — admin @ 22:27

wro4j

ThreadLocal

Archiviato in: java, oracle — Tag:, , , — admin @ 22:22

The javadoc says this:

“Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist).

If your application or (if you are talking about request threads) container uses a thread pool that means that threads don’t die. If necessary, you would need to deal with the thread locals yourself. The only clean way to do this is to call the ThreadLocal.remove() method.

There are two reasons you might want to clean up thread locals for threads in a thread pool:

to prevent memory (or hypothetically resource) leaks, or
to prevent accidental leakage of information from one request to another via thread locals.

Thread local memory leaks should not normally be a major issue with bounded thread pools since any thread locals are likely to get overwritten eventually; i.e. when the thread is reused. However, if you make the mistake of creating a new ThreadLocal instances over and over again (instead of using a static variable to hold a singleton instance), the thread local values won’t get overwritten, and will accumulate in each thread’s threadlocals map. This could result in a serious leak.

private void cleanThreadLocals() {
        try {
            // Get a reference to the thread locals table of the current thread
            Thread thread = Thread.currentThread();
            Field threadLocalsField = Thread.class.getDeclaredField("threadLocals");
            threadLocalsField.setAccessible(true);
            Object threadLocalTable = threadLocalsField.get(thread);

            // Get a reference to the array holding the thread local variables inside the
            // ThreadLocalMap of the current thread
            Class threadLocalMapClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap");
            Field tableField = threadLocalMapClass.getDeclaredField("table");
            tableField.setAccessible(true);
            Object table = tableField.get(threadLocalTable);

            // The key to the ThreadLocalMap is a WeakReference object. The referent field of this object
            // is a reference to the actual ThreadLocal variable
            Field referentField = Reference.class.getDeclaredField("referent");
            referentField.setAccessible(true);

            for (int i=0; i < Array.getLength(table); i++) {
                // Each entry in the table array of ThreadLocalMap is an Entry object
                // representing the thread local reference and its value
                Object entry = Array.get(table, i);
                if (entry != null) {
                    // Get a reference to the thread local object and remove it from the table
                    ThreadLocal threadLocal = (ThreadLocal)referentField.get(entry);
                    threadLocal.remove();
                }
            }
        } catch(Exception e) {
            // We will tolerate an exception here and just log it
            throw new IllegalStateException(e);
        }
    }

A good place to do such cleanup is ServletRequestListener.requestDestroyed().

24 marzo 2013

JD Decompiler for Eclipse 4.2 Juno

Archiviato in: java, sapere è potere — admin @ 12:48

1) download zip da qa
2) Eclipse > Help > Install new software > Add > Archive … selezionando il file zip scaricato al passo precedente
3) Eclipse > Window > Preferences > General > Editors > File Associations … selezionando ‘Class File Editor’ sia per ‘.class’ che per ‘.class without source’
4) restart eclipse

4 marzo 2013

Il codice muta ed io lo eSeguo

Archiviato in: code, java — Tag:, — admin @ 22:53

pitest && stackoverflow.

6 gennaio 2013

Android – Insufficient Permissions For Device

Archiviato in: java, linux — Tag:, — admin @ 16:05

run this command into shell:

> sudo adb kill-server
> sudo adb devices

4 ottobre 2012

Maven: aggiungere un file alla web-app con le svn info (version e path)

Archiviato in: java — Tag: — admin @ 09:47

<properties>
	<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
	<buildDateTime>${maven.build.timestamp}</buildDateTime>
</properties>

<build>
	<plugins>
		<plugin>
			<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
			<artifactId>svn-revision-number-maven-plugin</artifactId>
			<version>1.13</version>
			<executions>
				<execution>
					<goals>
						<goal>revision</goal>
					</goals>
				</execution>
			</executions>
			<configuration>
				<entries>
					<entry>
						<path>${project.basedir}</path>
						<prefix>a</prefix> <!-- this variable is used to populate version.xml -->
					</entry>
				</entries>
			</configuration>
		</plugin>
		<plugin>
			<artifactId>maven-antrun-plugin</artifactId>
			<executions>
				<execution>
					<phase>generate-sources</phase>
					<configuration>
						<tasks>
							<copy file="src/main/resources/version.template.xml" tofile="src/main/webapp/version.xml" overwrite="true" />
							<replace file="src/main/webapp/version.xml" token="${revision}" value="${a.revision}"/>
							<replace file="src/main/webapp/version.xml" token="${path}" value="${a.repository}/${a.path}"/>
							<replace file="src/main/webapp/version.xml" token="${timestamp}" value="${buildDateTime}"/>
						</tasks>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

3 ottobre 2012

Difference between ConcurrentHashMap and Collections.synchronizedMap

Archiviato in: java — Tag: — admin @ 19:05

read me

18 settembre 2012

Guice AssistedInject

Archiviato in: java — Tag:, , — admin @ 22:38
public class GuiceModule extends AbstractModule {
	@Override
	protected void configure() {

		bind(AuthService.class).to(RealAuthService.class);

		install(new FactoryModuleBuilder()
	    	.implement(Payment.class, RealPayment.class)
	    	.build(PaymentFactory.class));		

	}
}

public interface AuthService {
}

public class RealAuthService implements AuthService {
}

public interface Payment {
	void pay(BigDecimal amount);
}

public class RealPayment implements Payment {
	@Inject
	public RealPayment(AuthService authService, @Assisted BigDecimal amount) {
		System.err.println("create RealPayment with args");
		System.err.println("authService: " + authService);
		System.err.println("amount: " + amount);
	}

	@Override
	public void pay(BigDecimal amount) {

	}
}

public interface PaymentFactory {
	Payment create(BigDecimal amount);
}

public static void main(String[] args) {
	final Injector injector = Guice.createInjector(new GuiceModule());
	final PaymentFactory paymentFactory = injector.getInstance(PaymentFactory.class);

	System.err.println("create payment: " + paymentFactory.create(BigDecimal.TEN));
}

6 aprile 2012

pozzo

Archiviato in: code, java, linux — Tag: — admin @ 23:14

pozzo

Articoli precedenti »

Funziona con WordPress