[2018 oracle code one] mastering jpa performance

Mastering JPA Performance
Speaker: Thomas Broll
@speakjava

For more blog posts, see The Oracle Code One table of contents


Problem

  • Users complain
  • With microservices more important beause more calls

General

  • Apache lang has ImmutableTriple class

Techniques

  • Monior – number sql statemtenrs, cpu, i/o
  • hibernate.show_sql = true
  • run jstack while transaction running to see where stuck
  • Check JDBC driver batch size

Create – Performance improvements

Scenario: writing large amounts of data

  • Use table generator (vs sequence generator) where gt batch of ids so not a roud trip to get it each time. Even better to use external UUID generator
  • JPA only supports one open batch. But goes to database if do a query or persist a different entity. So faster if persist by entity

Read – Performance improvements

  • 1+N problem. One statement in code. Executes more statement to get relationships. All, XToOne are eagerly loaded
  • Can provide hints to eagerly or lazy load
  • fetch query to get data actually needed – can put it in the JQL query
  • Can get Hibernate statistics for number of queries/loads/fetches
  • Cal setFirstResult() and setMaxResults() on query object

Update – Performance improvements

  • Auto flushes are caused by transaction commit, insert/delete, query or explicitly flush()
  • Performance cost due to dirty checks and actual updates. Cost also depends on size of persistence context
  • Call getReference() to get empty proxy. This allows saving without changing in database?

Delete – Performance improvements

  • Remove() requires persistent entities, requires loading reference
  • Delete by query could be more efficient

Cloud

  • Two orders of maginude worse when database on different continent.
  • 35 minutes to do 5 second run when database on a different continent

My take: It’s been a while since I look at this topic. It was a good mix of review and things I never knew. Not having a physical network between the machine and database really hanges the numbers. It would have been nice to use a cloud database to get those numbers [scratch that; he did at the very end. I would have liked to see it earlier]

[2018 oracle code one] Java 9, 10 and 11: Pitfalls for the Unwary

Java 9, 10 and 11: Pitfalls for the Unwary
Speaker: Simon Ritter
@speakjava

For more blog posts, see The Oracle Code One table of contents


General

  • If you aren’t already on Java 9 or 10, don’t upgrade to them. Go straight to Java 11. Java 9 and 10 are feature releases, not LTS releases

Compatibility

  • Compatibility has always been very important
  • A few exceptions, but not significant. Was a pattern match search and replace
  • 1.4 – couldn’t use name assert anymore
  • 1.5 – couldn’t use name enum anymore
  • Concept of deprecation added in 1.1 – statement that a newer version is better
  • Java 8 has 492 deprecated API elements and non had ever been removed
  • Going forward, get at least one release or warning. Noted that less than that would be no warning at all.
  • Starting Java 9, things getting removed.
  • “if your code only uses standard Java APIs, it will most likely work” – Mark Reinhold

Java 9 – Module system

  • 75 OpenJDK modules
  • 27 Java SE, 48 JDK (ex: tools)
  • Oracle JDK adds 14 more JDK, 8 Java FX and 2 Oracle specific. Applies to Java 9. Remember Oracle JDK 11 == Open JDK 11
  • Most internal APIs are now encapsulated
  • sun.misc.Unsafe – the clue is in the name. Everyone has used through open source library like spring
  • Can choose not to use modules. Leave everything on classpath. Everything is in the unnamed module which depends on all modules. All packages are exported.
  • Then can migrate to modules gradually. Try automatic modules where don’t have module-info.class file but still treat as module.
  • Try moving existing jar files from classpath to modulepath.
  • “Big Kill Switch” –illegal-access
    • permit – warn for first use of encapsulated API
    • warn – warn for every use of encapsulated API
    • debug – warn and provide stack trace for every use
    • deny – don’t allow use at all
    • At some point, the default will become deny. We don’t know when. Suspect it’ll be a good while.
  • Allow direct access to encapsulated APIS — add exports
    • List package names exposing. Can be to ALL-UNNAMED or to specific packages
    • Alternatively can do this in the jar file manifest. That way library can expose without users having to specify
  • ‘Allow reflective access to encapsulated API –add-opens
    • List package names you want to expose
  • jdeps
    • find dependencies so can see which modules using
    • includes jdk.unsupported which is where sun.unsafe lives
  • java.se – aggregator module – If just use java.se, everything should just work
  • java.se.ee – module not included by default in JDK 9/10
    • ex: corba, transactions, Java activation (beans activation framework), xml bind (JAXB), web services (SOAP based)
    • Audience survey showed a lot of people using SOAP based web services
    • Still affected if use Apache SOAP library because sits on top of java library
    • Options
      • –add-modules – to explicitly add
      • Use standalone package from Maven central – deploy to upgrade module path or standalone version on classpath

Other changes

  • Single underscore is now a keyword. Can no longer use as an identifier. Can use two or more underscores if really want underscore variable name. Will be introducing _ as lambda dummy parameter.
  • Deleted some deprecated methods
  • New tool in Java 9: jdeprscan – static analysis against class files and jar files to report Java SE deprecated APIs
  • JDK/JRE file structure changed. Flatter directory structure. Now have bin/conf/lib/jmods.
  • lib/ext and lib/endorsed removed. If create directory, get fatal error starting JDK. Fails fast!
  • JNLP (Java Network Launch Protocol) – now uses strict parsing
  • Removed lots of JVM flags and others were replaced with different flags.

Version numbers

  • Version string format has changed. Was 1.8.0_131.
  • Fun fact. JDK 7u55 has more patches than JDK 7u60
  • New format $FEATURE.$INTERIM.$UPDATE.$PATCH
    • Feature – main version number
    • Interim – always 0 – reserved for future use
    • Update – 0, 1, 2
    • Patch – for emergency updates

JDK 10

  • var is now a reserved type. Not a reserved word. Can still use as variable name. Can’t create class called “var”.
  • Removed for deprecated code.
  • javah tool removed (for JNI). How do javac -h
  • policytool also removed

JDK 11

  • Oracle JDK – commercial license
  • Oracle Open JDK JDK – Mark Reinhold wants OpenJDK to be an adjective; not a noun. [because people are going to say that?}
  • Browser plugin going away
  • Java Web Start going away. Some alternatives, but no drop in replacement.
  • jmc (monitoring/mission control) – now a standalone package
  • More deprecated code removed

My take: Great humor. And great review for the stuff I knew. Also good clarifications and learning for the parts I did not know. There were a lot of references to Java 9 and 10. For most things, these apply to 11 as well. In a few case, it was confusing what applied to 11 vs what was interim.

[2018 oracle code one] augmented reality for the masses

Augmented Reality for the Masses
Speaker: Siamak Ashrafi
@biocodes

For more blog posts, see The Oracle Code One table of contents


Imagination

  • Imagination is the beginning of science
  • Imagination will spark AR (augmented reality) on mobile
  • Imagination is not limited. Can grow it.
  • Necessity is not the mother of invention. It is plausible intellectual curiosity
  • Science fiction has to be rooted in plausible science. Many famous sci fi authors have science educational background
  • Arthur C Clarke’s rules:
    • When a distinguished elderly scientist states something possible, usually right. When says impossible, probably wrong
    • Way of discovering limits of possible is to venture a little past them into impossible
    • “Any sufficiently advanced technology is indistinguishable from magic”
  • Magic/imagination/design/science have a positive feedback loop
  • “Truth is stranger than fiction, but it is because Fiction is obliged to stick to possibilities. Truth isn’t” – Mark Twain.

Initial AR to present

  • 1901 – First mention of concept in Wizard of Oz. Marker on forehead about moral character. Read using electronic spectacles.
  • 1957 – First patent in space of AR
  • 1992 – Term coined by Tom Caudell at Boeing
  • 2007 – Smartphones exploded giving sensors and power needed to bring to the masses
  • Humans think linearly. So we overhype at beginning and then it exponentially grows and disruption happens. Currently in development phase.
  • Last year, Lowe’s started where can view your kitchen with the new products in AR.
  • This year presented at medical conference.
  • Apple and Google will bring to masses
  • Other early examples – virtually try on clothes, tell you about interest facts nearby, lanes least crowded in front of you (but caused traffic jam from everyone moving there)
  • Arise game – can only cross bridge when it is solid. Which depends on perspective. [I don’t get how this is AR. It seems like a game independent of the real world]

AR vs VR

  • AR – still living in real world. Digital information. Mixed mode
  • VR – for living in a new world – isolates from everything around. Covers eyes/ears.
  • AR on phone isn’t user friendly because awkward to hold phone in front of us.

Referencing locations

  • Fiducial markers – object uses for reference. Mattel used to play virtual Rock Em Sock Em robots. Just printed out a “map” and two people could play on phones
  • GPS markers – actual location
  • Legacy mixare.org – used camera/compass/etc to do markers around you

Technologies

  • Tango 3D Mapping – 7 degrees of freedom.
  • Google killed Tango phone in less than a month.
  • Superseeded by AR Core
  • IMU – Inertial Measurement Unit – reports force/rate and sometimes magnetic field. Humans do this automatically. Uses dead reckoning.
  • With one camera can capture two (or more) frames. Build point cloud to see what pixels same and where moved. Doesn’t work with low light/shadows/on tripod.

AR Core

  • Motion tracking – pose (position and orientation of phone). Also COM (concurrent odometer and mapping) to keep virtual objects in right position. Hard math
  • Environment understanding – detect horizontal services so can put objects on them
  • Light estimation – make virtual objects right brightness for ambient light

AR KIt

  • iOS library. Supports iPhone 6s+ and old iPads (and current ones)
  • Same terminologies and principles as AR Core.
  • Library existed before AR Core.
  • AR Kit 2 came out recently – adds sharing experience. Can save/reuse environment.

Code/Getting started

  • Repo: https://github.com/google-ar/arcore-android-sdk
  • coursera.com/learnar
  • 90 line program
  • Have XML AR fragment
  • Then build model
  • Many models available online

Demo

  • He said the demo always crashes his machine. Running on beta version of OS/emulator/plugin [good to do with 4 minutes left then!]
  • Three calls in Android app – load fragment, create model and add listener. It’s about a page of code as two of the calls have nested lines of code.
  • Solar system with multiple models what build on each other.
  • Built point cloud. Use virtual sensors using IDE controls.

My take: He did a plug for voting thumbs up before actually starting. I don’t think I’ve seen that approach before. I was more interested in the higher level, but it was cool to see the details of the Android library as well. The speaker said he was surprised to have an Android talk accepted. I’m not. It’s in the ecosystem. Overall, it was cool seeing what’s out there.