Friday, November 23, 2012

Eclipse - “Show heap status”

One of the problems people complain about when starting with Eclipse is that it is slow. Then if you search the web you are advised to allocate more memory (RAM) to Eclipse (Java), but how much should you really?

Well, it all depends on the size of your project and the plugins that you use. Allocate too little and Java Garbage Collector will consume a lot of CPU going through the heap trying to remove discarded objects to make room for new ones, allocate too much than you system has free (available) and it will swap extensively to disk (“swap” file) to give you more free RAM.

How would you know if you allocated enough to Eclipse or you might need to allocate more (provided that you see you have the free memory available). This is where Eclipse “show heap status” feature comes in handy.

First of all you need to enable it: Windows > Preferences > General > Show heap status. It will show this little graph in the status bar:
  • left area (lighter) is how much heap it uses at the moment.
  • right area (darker if you right-click it and check show “Heap Max”) is how much is available from what pre-allocated (either through –Xms startup parameter or pushed past –Xms towards –Xmx)
  • hover to get the details in a tooltip;
  • click the garbage can to force a Garbage Collection.

Then look at it while using the project (build etc) – if the heap usage goes towards maximum, the colour will turn red showing that it might be struggling. You can force a garbage collection using the “garbage can”, but that’s a workaround just to finish the job instead of having to restart Eclipse. Use it too much and the JVM will pause to force an early GC.

In my example I have both minimum (-Xms) and maximum (-Xmx) heap size set to the same values (384MB) and at that moment was only using 41 MB out of it (it pre-allocated though the minimum from the system at startup). As you will be using the project it will go up and down, as needed and as GC will do it’s job.

C:\Program Files\Java\jdk1.7.0_09\jre\bin\server\jvm.dll
So why is my eclipse.exe (javaw.exe) process using 600 MB of RAM when I’ve set my heap to 384 MB? It’s because Heap is not everything, there’s also the Permanent Generation (PermGen) and a few other things, so consider those as well when you decide to increase heap. On Windows use a tool like Process Explorer to see all these details – system commit, free RAM, process private bytes, working set etc.

Wednesday, November 14, 2012

GameTrailers Android app - Google Play DMCA Notice

A disgruntled user or maybe a Viacom employee has reported all GameTrailers apps in Google Play for copyright infringement, which in their turn have suspended the application, possibly to be followed by suspension of my Google Play account if not my entire Google Account, with the worst case scenario followed by a law-suit (I will gladly give them my $1.11 gained from ads, although they probably won’t settle just for that).

So kids, the lesson here is don’t do it (GameTrailers Terms & Conditions : “We take protection of copyrights, both our own and others, very seriously”). Fully linking to their website is probably not enough and using their logo probably makes it worse.

So unless you’ve got an iPhone (app) or tablet (web), you’re on your won. And wish me luck!

* * *

Subject: Google Play DMCA Notice

This is a notification that your application, GameTrailers, with package ID com.dandar3.gametrailers, has been removed from the Google Play Store.

REASON FOR REMOVAL: Alleged copyright infringement (according to the terms of the Digital Millenium Copyright Act).

All violations are tracked. Serious or repeated violations of any nature will result in the termination of your developer account, and investigation and possible termination of related Google accounts. Please review the Developer Distribution Agreement and Content Policy to ensure that your applications are compliant with our policies.

The DMCA is a United States copyright law that provides guidelines for online service provider liability in case of copyright infringement. Click here for more information about the DMCA, and see for the process that Google requires in order to make a DMCA complaint.

Google may reinstate your application into the Google Play Store upon receipt of a counter notification pursuant to sections 512(g)(2) and (3) of the DMCA. Click here for more information about the requirements of a counter notification and a link to a sample counter notification. If you have legal questions about this notification, you should retain your own legal counsel.

Please note that we have included a text copy of the Infringement Notice we received for your reference.

The Google Play Team

Text copy of DMCA complaint:

Dear Sir/Madam:

I am contacting you on behalf of Viacom International, Inc. (Viacom).  Under penalty of perjury, I assert that Viacom is authorized to act on behalf of the owner of the exclusive copyrights and trademarks that are alleged to be infringed herein.

Viacom has become aware that the Google Play network is hosting infringing Android applications that are listed on the spreadsheet that is attached to and is a part of this letter.  Those infringing applications contain exclusively owned Viacom character images; photographic images; character voices and sounds; storylines; video clips; show quotes; and/or songs.

I have a good faith belief that the Viacom property and material, which is described above, has not been authorized for use as part of the applications, which are listed and described on the attached spreadsheet, by the copyright owner, its agent, or the law.  I also assert that the information contained in this notice is accurate to the best of my knowledge.

We are requesting that you remove and disable access to the Android applications on the attached spreadsheet and delete the account.  We also request that you inform the application developer of the illegality of his/her conduct.

In complying with this notice, Google should not destroy any evidence, which may be relevant in a lawsuit, relating to the infringement alleged, including all associated electronic documents and data relating to the presence of infringing items on the Google Play web site, which shall be preserved while disabling public access irrespective of any document retention or corporate policy to the contrary.

Please note that this letter is not intended as a full statement of the facts; and does not constitute a waiver of any rights to recover damages incurred by virtue of any unauthorized or infringing activities occurring on your network.  All such rights, as well as claims for other relief, are expressly reserved.

Please confirm your compliance with our request within three days of receipt of this correspondence.  You may contact me to discuss this notice at Viacom International, Inc., 1515 Broadway, New York, NY, 10036, telephone, (000) 000-0000.  Or, you can send me an e-mail at

Very Truly Yours,
xxxxxxxxx, Esq.
Vice President, Anti-Piracy
Viacom Media Networks
1515 Broadway
New York, NY 10029

Tuesday, November 13, 2012

JBoss – Spring JDBC SQL logging (log4j)

You might occasionally need to investigate your application on a customer site (or even in your development environment look at parts of the application you’re not familiar with) from the outside first to see what they do in terms of SQL statements, before diving into the code.

Obviously a solution is to trace the statements at database level, but some databases make it easier than others or might require profiling rights and so on. But what you might have access to is your application log4j configuration.

Here’s an example on how to enable SQL logging for Spring JDBC into a separate file appender.

Note that I defined the loggers so they don’t inherit the appenders from parent packages or the root appenders (additivity=”false”) – you can remove that and they will append to predefined appenders as well as this new one. Whenever finished you can raise the level for those two loggers back to WARN to stop the logging, and if you need to leave it on for longer, see the previous post on how to roll logs. It’s probably not recommended though leaving the SQL logging on in production as it might slow the application or will produce large logs in busy environments.
<appender name="FILE_SQL" class="org.jboss.logging.appender.RollingFileAppender">
   <param name="File"      value="${jboss.server.home.dir}/log/sql.log"/>
   <param name="Threshold" value="TRACE"/>
   <param name="Encoding"  value="UTF-8" />

   <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d %-5p (%t) [%c:%L] %m%n"/>


<!-- SQL logging -->
<logger name="org.springframework.jdbc.core.JdbcTemplate" additivity="false">
  <priority   value="DEBUG"/>
  <appender-ref ref="FILE_SQL"/>

<logger name="org.springframework.jdbc.core.StatementCreatorUtils" additivity="false">
  <priority   value="TRACE"/>
  <appender-ref ref="FILE_SQL"/>
Sample output:
2012-11-13 16:51:01,969 DEBUG (http-8080-Processor18) [org.springframework.jdbc.core.JdbcTemplate:569] Executing prepared SQL statement [SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like ?]
2012-11-13 16:51:01,973 TRACE (http-8080-Processor18) [org.springframework.jdbc.core.StatementCreatorUtils:206] Setting SQL statement parameter value: column index 1, parameter value [Doe%], value class [java.lang.String], SQL type unknown

Thursday, November 1, 2012

JBoss – Daily rolling logs (log4j)

Our standard log4j JBoss application configuration uses with size based, index rolling file appenders, and when having to investigate customers issues that happened a few days back requires quite a bit of navigation to find the particular date and time, or worse if a recurrent problem fills up the log parts, it might loose the information that could’ve otherwise helped. So recently I’ve been looking to implement daily rolling file appenders in a customer site.

Looking at Log4j DailyRollingFileAppender they are advising to use the log4j extras companion classes:
DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user chosen frequency. DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org.apache.log4j.rolling.RollingFileAppender.
You can download the Apache Extras Companion for Apache Log4j from project website, or otherwise from - place that in your JBoss / application CLASSPATH and restart the application.

The RollingFileAppender uses a TimeBasedRollingPolicy, controlling when the file is rolled through a SimpleDateFormat pattern (daily, hourly etc). Optionally it can compress the archive log by adding the .gz/.zip extension to the filename. You can also move the archive logs into a separate location.
   <!-- SERVER.LOG -->
   <appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
     <!-- Active log file name -->
     <param name="File"     value="${jboss.server.home.dir}/log/server.log" />
     <param name="Append"   value="true" />
     <param name="Encoding" value="UTF-8" />

     <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
       <!-- Archive file to roll to @ midnight (yyyy-MM-dd) with compression -->
       <param name="FileNamePattern" value="${jboss.server.home.dir}/log/archive/server.%d{yyyy-MM-dd}" />

     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d %-5p [%t] [%c{1}:%L] %m%n"/>