tag:blogger.com,1999:blog-78646043158478024092008-05-16T13:11:03.912+02:00Inside JavaBlackBeltNicolas Brasseurhttp://www.blogger.com/profile/01117035593921786099noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-7864604315847802409.post-40523833345466433062008-05-16T13:00:00.001+02:002008-05-16T13:10:48.584+02:00You must obey the rules !With the upcoming revamp of the moderation process, here at the JavaBlackBelt <a href="http://www.javablackbelt.com/blog/atomium.jpg">secret HQ</a> we are fiercely arguing on <span style="font-weight: bold;">What Makes A Question Good</span>. I've summed up our discussions in the form of rules and have decided to share them with the community in this blog entry.<br /><ol><li>A question must be in the <span style="font-weight: bold;">right place</span>. A major problem in the basic exams is that many questions are too hard for the category they're in.</li><li>The question's statement must be clear, easy-to-understand, well-formatted, typo-free and focussed on testing real knowledge.<br /><span style="font-weight: bold;">Avoid ambiguity</span>: nothing is worse than knowing the answer but hesitating to state it because it's unclear what the question author wants. Example: "How old is J2SE?"<br /><span style="font-weight: bold;">Avoid trick questions</span>: does a question test the user's attention rather than her technical knowledge?<br /><span style="font-weight: bold;">Avoid never-ending questions</span>: questions containing too much text/code/choice are usually of poor quality.</li><li>Avoid <span style="font-weight: bold;">cut &amp; paste code</span> questions : ask yourself "Is it easy to find the right answer without even understanding why the answer is right, simply by pasting into an IDE or googling for 10 seconds?"</li><li>A question must include a <span style="font-weight: bold;">clear and pedagogical explanation</span> that will teach the user something. We aim to teach people new things.</li><li>Don't copy other people's questions. <span style="font-weight: bold;">Plagiarism is evil</span>.<br /></li></ol>You must obey the rules !<br /><br />We've built JavaBlackBelt as a learning tool where people play with exams to discover new things. Help them in their journey. The main mantra when you write a question should be <span style="font-weight: bold;">"Do not try to trap people but, on the contrary, help them learn and understand the technology."</span>Nicolas Brasseurhttp://www.blogger.com/profile/01117035593921786099noreply@blogger.comtag:blogger.com,1999:blog-7864604315847802409.post-39296802977719012162008-05-09T08:30:00.001+02:002008-05-11T18:56:39.994+02:00Singing about architecture is like...<a href="http://globalnerdy.com/2007/11/28/dilbert-on-extreme-and-agile-programming/">Extreme Programming</a> and <a href="http://dilbert.com/strips/comic/2008-04-15/">stand-up meetings</a> have appeared in Dilbert over the years, but there's a new reference point to prove that software development methodology is a hot topic in mainstream pop culture: <a href="http://www.youtube.com/watch?v=k2CFDsG_oxg">"The Architect"</a> by <a href="http://www.myspace.com/deusbe">dEUS</a> (one of Belgium's best-known rock bands - which sounds like an insult, but isn't... I hope):<br /><br /><object height="355" width="425"><param name="movie" value="http://www.youtube.com/v/k2CFDsG_oxg&amp;hl=en"><param name="wmode" value="transparent"><embed src="http://www.youtube.com/v/k2CFDsG_oxg&amp;hl=en" type="application/x-shockwave-flash" wmode="transparent" height="355" width="425"></embed></object><br /><br />There's more to the song than a catchy guitar riff that's both dissonant and jerkily propulsive, it's clearly lambasting <a href="http://www.waterfallmanifesto.org/">Waterfall</a>, <a href="http://en.wikipedia.org/wiki/Big_Design_Up_Front">Big Design Up Front</a> and <a href="http://www.joelonsoftware.com/articles/fog0000000018.html">Architecture Astronauts</a>. Check out some of the <a href="http://www.hotellounge.com/songs/thearchitect.html">lyrics</a>:<br /><br /><blockquote>What is the architect doing?<br />(...)<br />I'm gonna go home and shut up for a year<br />And when that year is over I will reappear<br />And have a solution.<br />I've reason to believe that what I find<br />Is gonna change the face of human kind<br />(...)<br />Cause I'm the architect.<br />(...)<br />About all the problems on this earth we should<br />Worry now to solve them later<br />And so he’s brooding and alluding on a perfect design.<br />(...)<br />Now if these aspirations bother you<br />Well you are just you, you don’t have a clue<br />I'm sticking to the plan, I will see it through<br />Let there be no confusion.<br />Cause I'm the architect.</blockquote><br />It may only be software development, but at least now it's rock 'n' roll, too.Moandji Ezanahttp://www.blogger.com/profile/15146694874856243257noreply@blogger.comtag:blogger.com,1999:blog-7864604315847802409.post-65395137263814762262008-05-07T12:01:00.000+02:002008-05-07T12:01:00.689+02:00JUnit and auto-boxingAfter that gigantic <a href="http://www.javablackbelt.com/blog/2008/04/tomcat-memory-leak.html">previous post</a>, I thought it'd be good to post something simpler and more widely applicable.<br /><br />I came across a little JUnit assertion gotcha that had me puzzled for a second. I was testing this (note, calculateDurationInSeconds() returns a long)<br /><blockquote>assertEquals(120, subjectUnderTest.calculateDurationInSeconds());</blockquote>and getting the following, less-than-helpful test failure message<br /><blockquote>expected: <120> but was: <120></blockquote>I figured this one out pretty quickly because my Eclipse underlines cases of auto-boxing/unboxing. Since the assertEquals(Object, Object) method is being used, my int is becoming an Integer and the long returned by the method is becoming a Long. Obviously, any equals() comparaison is going to fail. I corrected this by using the long literal notation:<br /><blockquote>assertEquals(120L, subjectUnderTest.calculateDurationInSeconds());</blockquote>What with all the conversion already going on between the presentation and data layers, I'm trying to generalise the practice of making primitive/wrapper conversions explicit, just in case.Moandji Ezanahttp://www.blogger.com/profile/15146694874856243257noreply@blogger.comtag:blogger.com,1999:blog-7864604315847802409.post-63313090411747527332008-05-05T18:16:00.001+02:002008-05-06T10:31:10.218+02:00How Tomcat ruined my nightTomcat is probably <a href="http://blog.springsource.com/main/2007/12/24/is-it-a-tomcat-or-the-elephant-in-the-room/">one of the more widely used pieces of open source infrastructure</a> and it's a great boon to our productivity. Sometimes, though, a deep-rooted problem can sneak up on you and drag you into a sleep-deprived night of frantic web searching.<br /><br />One day, I happened to see our production JVM restart, for no apparent reason. Intrigued, I looked into it a little bit more and realised that since <a href="http://www.javablackbelt.com/NewsletterPreview.wwa?newsletterId=5819858">the release of JBB v3</a> last December, it had been restarting roughly 6 times per month. After an OutOfMemory, <a href="http://blogs.sun.com/alanb/entry/heap_dumps_are_back_with">the JVM dumps its heap into an hprof file</a>, so there were a number of these files on the server, often over 1GB each!<br /><br />I downloaded an hprof file and tried to open it with <a href="https://hat.dev.java.net/">jhat</a>, provided with the default Java 6 distro. jhat creates a website for you to visualise the heap [1]. Unfortunately, I couldn't get jhat to work, probably because <a href="http://blogs.sun.com/alanb/entry/heap_dumps_are_back_with#comment-1174977909000">JavaScript support is not yet implemented in MacOSX's JDK 1.6</a>. I got around this problem by reading the hprof with <a href="http://yourkit.com/">YourKit Java Profiler 7.0</a> and quickly saw that vast amounts of memory were being taken up by several huge char arrays (click on the image for a larger version).<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.javablackbelt.com/blog/uploaded_images/yourkit_sc-743134.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://www.javablackbelt.com/blog/uploaded_images/yourkit_sc-743123.jpg" alt="" border="0" /></a><br /><br />As you can see from the screenshot, 115 instances of <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/jasper/runtime/BodyContentImpl.html">org.apache.jasper.runtime.BodyContentImpl</a> were holding on to over 560 million bytes worth of objects, keeping them from being garbage-collected and eating up inordinate amounts of RAM. So, what's BodyContentImpl actually doing?<br /><br />Tomcat maintains a pool of PageContext instances, which in turn have an array of BodyContentImpls. Each BodyContentImpl has an array with the text from the tag's body. This array has a default size of 512 that is hard-coded as org.apache.jasper.Constants.DEFAULT_TAG_BUFFER_SIZE. Once the body of a custom tag gets bigger than that, the array grows and is never reset to its original size. With concurrent users, several such arrays might be created, so if a few popular pages use big custom tags, you can end up with a number of gigantic, un-garbage-collectable char arrays. In our case, this happened because in v3 we started decorating large blocks of JSP code with SiteMesh custom tags.<br /><br />One solution would be to set the environment variable org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER to true, so that arrays over 512 bytes are released. Another would be to recompile Tomcat with a tag buffer size more suited to our needs. So both choices are extreme: either you maintain huge arrays for ever, or you're constantly creating and garbage collecting arrays, as 512 bytes is a fairly low limit for custom tags. We settled on giving the JVM more RAM to handle the extra garbage collection.<br /><br />Of course, <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=37793">others</a> have <a href="http://jira.atlassian.com/browse/JRA-10145">experienced</a> the same problem<a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=37793"></a>. What's the word from the Tomcat camp? Well, Remy Maucherat, Tomcat committer, <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=37793#c8">considers that</a>: <blockquote>Using sensibly written software helps. It should be obvious reading the API that using large body tags is going to be a huge problem.<br /></blockquote>Please draw your own conclusions.<br /><ol><li><span style="font-size:85%;">By the way, jhat loads the whole hprof file into memory, so you may need to use the -J-mx512m flag if you're having OutOfMemory thrown.</span></li></ol>Aymeric Levauxhttp://www.blogger.com/profile/15554948182907260874noreply@blogger.comtag:blogger.com,1999:blog-7864604315847802409.post-18689076482012762642008-04-30T10:52:00.000+02:002008-04-30T11:04:22.324+02:00Welcome!Welcome to <a href="http://www.javablackbelt.com/">JavaBlackBelt</a>'s new blog!<br /><br />The aim and content are likely to evolve, but at the moment, we plan to write about some of the interesting technical issues Aymeric and I face developing the website, along with tips and tricks/how-to posts to help you get the most out of JBB.<br /><br />Please leave comments, bookmark us, subscribe to the <a href="http://www.javablackbelt.com/blog/atom.xml">RSS feed</a>, share us on your favourite social networks and whatever else people are doing to blogs nowadays. We hope you enjoy delving Inside JavaBlackBelt!Moandji Ezanahttp://www.blogger.com/profile/15146694874856243257noreply@blogger.com