XPath mit der Powershell
test.xml:
<a><b x='42'/></a>
Datei laden:
$xml = [xml] (gc ".\test.xml")
Und ab dafür:
$xml.SelectNodes('/a/b') | % { echo $_.x }
Doppelte Einträge in unsortierter Aufzählung
Auffinden von Dubletten mit der Powershell:
get-content in.txt | sort | group | ? {$_.count -gt 1} | % {$_.name} > out.txt
Wobei ? eine Abkürzung für Where-Object und % eine Abkürzung für Foreach-Object ist.
(get-alias -name %)
Unexpected Reader – Hibernate can’t get enough of my diploma thesis
This morning i burned a lot of houres fixing an issue during the startup of a small jboss application. Actually it only was a testing project including a single SessionBean, a Servlet and last but not least an EntityBean that should be persisted using JPA/Hibernate. This project lived in the “scratchpad”-folders of my source directories and the reason for its existence only was to play around a little bit with transactions in a certain setting of my jboss-server. It was not ment for bothering me more than one houre. But … !
To fake a fileupload and other activity to some service, i wanted to place some file as a resource within the ejb-jar of the application. The first document i found on my harddrive was my diploma thesis, which is an pdf of about 8MB. It was placed in the same jar that also holds the EntityBean and the corresponding persistence.xml.
As i deployed the application the first time i noticed a two minute break in my server.log after the message:
... (HDScanner) Starting persistence unit persistence.unit ...
and top told me that the CPU was running on 100%.
Two houres later after checking my persistence.xml, my Beans and Annotations and the database, I started a debugger, suspended thread by thread and watched the CPU usage.Thus I found a
org.hibernate.ejb.packaging.JarVisitorFactory
that was reading my diploma thesis in packages of 4kb. I know that my thesis is interessting but not for a hibernate deployment thread that was meant to be scan for @Entity annotations. I also found some interesting comment:
//this is bad cause we actually read everything instead of walking it lazily
So every thing you bundle in your jar will be scanned by hibernate. I know that it’s not best practise to put huge pdf files within your application, but what about a war file holding a bunch of icons etc.
Nice to know.
(I used jboss-5.1.0.GA including hibernate-entitymanager-3.4.0.GA.)
Java Remote Debugging
This line somtimes disappears from my bash history:
export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=n -XX:MaxPermSize=1024m"