Wednesday, August 12, 2015

An interesting JDK6 bug about EventDispatchThread

An interesting JDK6 bug about EventDispatchThread

0. Background
Need add read only access control for legacy Java Swing modules.

1. What's the issue
To avoid the changes scattered in many places, ReadonlyException is defined and DefaultUncaughtExceptionHandler is set in one place. It looks good
except for the modal popup dialog. There's a message on console:
Exception occurred during event dispatching:...

2. What's the cause
The message comes from EventDispatchThread.java:
            if (isModal) {
                System.err.println(
                    "Exception occurred during event dispatching:");
                e.printStackTrace();
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException)e;
            } else if (e instanceof Error) {
                throw (Error)e;
            }
    if it's a modal dialog, the exception will be captured by EDT, the problem is that EDT does not pass it to UncaughtExceptionHandler like JDK7 or JDK8:
getUncaughtExceptionHandler().uncaughtException(this, e);

3. How to fix
By debugging/tracking the JDK source code, we can set property "sun.awt.exception.handler" but even after I set the property, issue is still there.
Checking the EventDispatchTread.java source again, and there's a block:
       try {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                Class c = Class.forName(handlerClassName, true, cl);
                m = c.getMethod("handle", new Class[] { Throwable.class });
                h = c.newInstance();
            } catch (Throwable x) {
                handlerClassName = NO_HANDLER; /* Do not try this again */
                return false;
            }
It means that it will invoke the handler's handle method, and the handler must have a non-parameter construtctor. The worst thing is that it does not print any
error message when the exception happens. Until I checked here, I realized I need add a non-parameter construtctor to the handler.

4. More about the bug:
http://bugs.java.com/view_bug.do?bug_id=6727884
I verified it worked perfect on JDK8 without the workaround and it failed to show the popup message on JDK6 without the workaround.

How to debug JDK source code:
1. Unzip src.zip and create a java project in Eclipse, set the source to the unzipped src folder
2. If there's compilor error (...is not accessible due to restriction...), remove JRE library and add them back to let Eclipse use the right class first
3. Export the jar file and put it into %JDK%\jre\lib\endorsed. Create endorsed folder if it's not there. We don't have permission to operate on the default
JDK home, so need to set JDK home to other place.

JQuery note

jQuery Syntax

1. Basic syntax is: $(selector).action()
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".

2. It is good practice to wait for the document to be fully loaded and ready before working with it.
$(document).ready(function(){
   // jQuery methods go here...
});
The jQuery team has also created an even shorter method for the document ready event:
$(function(){
   // jQuery methods go here...
});

3. More Examples of jQuery Selectors
$("*") Selects all elements
$(this) Selects the current HTML element
$("p.intro") Selects all <p> elements with class="intro"
$("p:first") Selects the first <p> element
$("ul li:first") Selects the first <li> element of the first <ul>
$("ul li:first-child") Selects the first <li> element of every <ul>
$("[href]") Selects all elements with an href attribute
$("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"
$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"
$(":button") Selects all <button> elements and <input> elements of type="button"
$("tr:even") Selects all even <tr> elements
$("tr:odd") Selects all odd <tr> elements

4. Three simple, but useful, jQuery methods for DOM manipulation are:
text() - Sets or returns the text content of selected elements
html() - Sets or returns the content of selected elements (including HTML markup)
val() - Sets or returns the value of form fields
The jQuery attr() method is used to get attribute values.
four jQuery methods that are used to add new content:
append() - Inserts content at the end of the selected elements
prepend() - Inserts content at the beginning of the selected elements
after() - Inserts content after the selected elements
before() - Inserts content before the selected elements
remove() - Removes the selected element (and its child elements)
empty() - Removes the child elements from the selected element
$("p").css("background-color", "yellow");

5. sample list
http://www.w3schools.com/jquery/jquery_examples.asp

Sunday, August 9, 2015

32位XP 下安装64位win7 双系统

直接安装不了,因为32位系统下不支持64位的系统安装,去网上找一个nt6 hdd installer软件,把你下载的安装版的WIN7解压到你要安装的盘根目录下,再运行nt6 hdd installer,重启就可以自动安装了

http://zhidao.baidu.com/question/175322484.html?qbl=relate_question_2&optimi=4

Friday, August 7, 2015

osgi note

Eclipse osgi implementation changes to rely on Apache felix gogo project. So cannot start osgi console in the below way:
java -jar org.eclipse.osgi_3.10.100.v20150529-1857.jar -console
osgi prompt will not appear.
Need copy the 4 files (org.eclipse.osgi and gogo):
org.eclipse.osgi_*.jar, org.apache.felix.gogo.*.jar
Then create a configuration folder and put a file config.ini with the below content:
osgi.bundles=org.eclipse.osgi_3.10.100.v20150529-1857.jar@start,org.apache.felix.gogo.shell_0.10.0.v201212101605.jar@start,org.apache.felix.gogo.runtime_0.10.0.v201209301036.jar@start,org.apache.felix.gogo.command_0.10.0.v201209301215.jar@start
When osgi prompt appears, type help to show the available commands.
https://isurues.wordpress.com/2009/01/01/useful-equinox-osgi-commands/

By default, none of the classes in a bundle are visible from any other bundle; inside bundles they follow the normal rules of the Java language.
So, what do you do if you want to access the classes of one bundle from another bundle?
The solution is to export packages from the source bundle and then import them into the target bundle.
The OSGi container creates a different class loader for every bundle.

Thursday, August 6, 2015

CPP_note

http://www.cplusplus.com/doc/tutorial
1. cin and strings
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string mystr;
  cout << "What's your name? ";
  getline (cin, mystr);
  cout << "Hello " << mystr << ".\n";
  return 0;
}

2. stringstream
string mystr ("1204");
int myint;
stringstream(mystr) >> myint;

3. passed by reference
#include <iostream>
using namespace std;

void duplicate (int& a, int& b, int& c)
{
  a*=2;
  b*=2;
  c*=2;
}

int main ()
{
  int x=1, y=3, z=7;
  duplicate (x, y, z);
  cout << "x=" << x << ", y=" << y << ", z=" << z;
  return 0;
}
By qualifying them as const, the function is forbidden to modify the values of neither a nor b, but can actually
access their values as references:
string concatenate (const string& a, const string& b)
{
  return a+b;
}

4. function template (are_equal(10,10.0) Is equivalent to: are_equal<int,double>(10,10.0))
#include <iostream>
using namespace std;

template <class T, class U>
bool are_equal (T a, U b)
{
  return (a==b);
}

int main ()
{
  if (are_equal(10,10.0))
    cout << "x and y are equal\n";
  else
    cout << "x and y are not equal\n";
  return 0;
}

5. pointer
#include <iostream>
using namespace std;

int main ()
{
  int firstvalue, secondvalue;
  int * mypointer;

  mypointer = &firstvalue;
  *mypointer = 10;
  mypointer = &secondvalue;
  *mypointer = 20;
  cout << "firstvalue is " << firstvalue << '\n';
  cout << "secondvalue is " << secondvalue << '\n';
  return 0;
}

The arrow operator (->) is a dereference operator that is used exclusively with pointers to objects that have members.
movies_t * pmovie;
pmovie->title is, for all purposes, equivalent to: (*pmovie).title

6.
Classes are an expanded concept of data structures: like data structures, they can contain data members,
but they can also contain functions as members.
empty parentheses cannot be used to call the default constructor:
Rectangle rectb;   // ok, default constructor called
Rectangle rectc(); // oops, default constructor NOT called

Remote debug on asset control

Same method to remote debug on asset control, Eclipse or other osgi based application.

Add the below on ac.desktop.ini (or Eclipse.ini):
-Xdebug
-Xnoagent
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000

Start the debug from Eclipse.

Tuesday, August 4, 2015

Australia trval

www.wotif.com
surfers paradise
apartment self contained
great barrier reef