90 likes | 242 Views
Objectivity/DB & JAVA. by Antek Baranski Norsys Technology AB. Overview. Objy class registration. JAVA reflections. JAVA GC. Non-recursive tree traversal. Objy class registration. Can be slow. Do it up-front. i.e. on creating the connection, with registerClass. How does it work?
E N D
Objectivity/DB & JAVA by Antek Baranski Norsys Technology AB Objectivity/DB & JAVA
Overview • Objy class registration. • JAVA reflections. • JAVA GC. • Non-recursive tree traversal. Objectivity/DB & JAVA
Objy class registration • Can be slow. • Do it up-front. • i.e. on creating the connection, with registerClass. • How does it work? • VM and Objy Schema class comparison. • field - field comparison. • Inheritance tree. • i.e. JAVA reflection. Objectivity/DB & JAVA
JAVA reflections • Expensive. • High memory usage. • Slows down JAVA VM. • JAVA GC works overtime. • Unpredictable application performance. • Possible solution: • “Pre”-reflect all classes on class-registration. • Pity we can’t use Objy registerClass reflections. Objectivity/DB & JAVA
JAVA GC • Application performance unpredictable. • JAVA 1, up to 30% difference. • JAVA 2, ‘only’ 13% difference. • Possible solution call GC yourself. publicstaticvoid yieldToGC() { Thread myThread = Thread.currentThread(); int myPriority = myThread.getPriority(); myThread.setPriority(Thread.MIN_PRIORITY); System.gc(); myThread.yield(); myThread.setPriority(myPriority); } Objectivity/DB & JAVA
Non-recursive tree traversal (1) publicclass TIterator { publicint parentItr = -1; publicint childItr = -1; publicint scope = 0; public com.objy.db.app.Iterator itr = null; public TIterator() { parentItr = -1; childItr = -1; scope = 0; itr = null; }; public TIterator(com.objy.db.app.Iterator itrIn) { parentItr = -1; childItr = -1; scope = 0; itr = itrIn; }; public TIterator(int parent, int level, com.objy.db.app.Iterator itrIn) { parentItr = parent; childItr = -1; scope = level; itr = itrIn; }; } Objectivity/DB & JAVA
Non-recursive tree traversal (2) publicboolean nextObj(int iterator) { int itr = 0; int parent = 0; int scope = 0; int child = 0; try { parent = this.itr[iterator].parentItr; scope = this.itr[iterator].scope; child = this.itr[iterator].childItr; if (child != -1) { while (this.itr[child].childItr != -1) { parent = child; child = this.itr[child].childItr; } if (this.itr[child].itr.hasMoreElements()) { moi = (MOInfo) this.itr[child].itr.nextElement(); if (moi.children.exists()) { if (this.itr[child].scope != 0) { itr = this.createItr(child, this.itr[child].scope, moi.children.scan()); this.itr[child].childItr = itr; } } returntrue; } // if (child != -1) Objectivity/DB & JAVA
Non-recursive tree traversal (3) this.deleteItr(child); while (parent != -1) { this.itr[parent].childItr = -1; if (this.itr[parent].itr.hasMoreElements()) { moi = (MOInfo) this.itr[parent].itr.nextElement(); if (moi.children.exists()) { if (this.itr[parent].scope != 0) { itr = this.createItr(parent, this.itr[parent].scope, moi.children.scan()); this.itr[parent].childItr = itr; } } returntrue; } child = parent; parent = this.itr[parent].parentItr; if (parent != -1) { this.deleteItr(child); } } } // while (parent != -1) Objectivity/DB & JAVA
Non-recursive tree traversal (4) if (this.itr[iterator].itr.hasMoreElements()) { moi = (MOInfo) this.itr[iterator].itr.nextElement(); if (scope != 0) { if (moi.children.exists()) { itr = this.createItr(iterator, scope, moi.children.scan()); this.itr[iterator].childItr = itr; } } returntrue; } returnfalse; } // try Objectivity/DB & JAVA