How to enable JMXRemote authentication and connect with JConsole

This tutorial will summarize how to setup a jmxremote access, so that a remote jconsole can be authenticated and connect.

We will be interested in 2 files, located in:
JAVA_HOME\jre\lib\management
  1. jmxremote.access
  2. jmxremote.password.template, rename to jmxremote.password
What needs to be done with these files:
  1. Add an admin role in jmxremote.access, so at the end you should see:
  2. monitorRole   readonly
    admin readonly
    controlRole readwrite \
    create javax.management.monitor.*,javax.management.timer.* \
    unregister
  3. Then we need to add the role and password in jmxremote.password
  4. monitorRole     secret
    controlRole secret
    admin secret
Then we need to restrict the owner's right to read-only, right clicking on the file and clicking read-only won't do. Need to execute the lines below:

cacls jmxremote.password /P :R
cacls jmxremote.access /P :R

Then for example I'm interested to monitor JBoss with JConsole. And I have added JBoss in eclipse's server view. I need to add the following in Program Arguments:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9001
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.ssl=false

Assumming I want to use port 9001.

Refer to the image below:

Finally run jconsole in command prompt, select org.jboss.xxx and enter our admin and password which is admin / secret.

JBoss datasource configuration settings

The following are sample configurations for different database (it's in the file standalone.xml subsystem=datasources):
H2, postgresql, mysql
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="false" jndi-name="java:jboss/datasources/PostgreDatasource" pool-name="PostgrePool" enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/postgre</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>postgre</user-name>
<password>postgre</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<background-validation-millis>1</background-validation-millis>
</validation>
<statement>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<datasource jta="false" jndi-name="java:jboss/datasources/mysqlDataSource" pool-name="mysqlPool" enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3306/mysql</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>mysql</user-name>
<password>mysql</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<background-validation-millis>1</background-validation-millis>
</validation>
<statement>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<datasource jndi-name="java:jboss/datasources/VmlaDS" pool-name="vmlaDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/vlma</connection-url>
<driver>mysql</driver>
<security>
<user-name>vlma</user-name>
<password>vlma</password>
</security>
<statement>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysql" module="com.sql.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
<driver name="com.mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
<datasource jndi-name="java:jboss/datasources/germ-popperDS" pool-name="GermPopperPool" enabled="true" use-java-context="true">
<connection-url>jdbc:jtds:sqlserver://localhost:1433/germpopper;loginTimeout=30;instance=sqlexpress</connection-url>
<driver>JTDS</driver>
<new-connection-sql>select 1</new-connection-sql>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>unicomi</user-name>
<password>unicomi</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
<timeout>
<set-tx-query-timeout>true</set-tx-query-timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>false</track-statements>
</statement>
</datasource>

Then add the following modules in: jboss-as-7.1.3.Final\modules
  1. postgresql
    1. create org/postgresql/main
    2. download and paste: postgresql-9.2-1002.jdbc4.jar
    3. create module.xml with these contents
    4. <?xml version="1.0" encoding="UTF-8"?>
      <module xmlns="urn:jboss:module:1.0" name="org.postgresql">
      <resources>
      <resource-root path="postgresql-9.2-1002.jdbc4.jar"/>
      </resources>
      <dependencies>
      <module name="javax.api"/>
      <module name="javax.transaction.api"/>
      </dependencies>
      </module>
  2. mysql
    1. create com/mysql/main
    2. download mysql-connector-java
    3. create module.xml with these contents
    4. <?xml version="1.0" encoding="UTF-8"?>  
      <module xmlns="urn:jboss:module:1.0" name="com.mysql">
      <resources>
      <resource-root path="mysql-connector-java-5.1.21.jar"/>
      </resources>
      <dependencies>
      <module name="javax.api"/>
      </dependencies>
      </module>
  3. MSSQL

  4. <driver name="JTDS" module="net.sourceforge.jtds">
    <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
    <xa-datasource-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</xa-datasource-class>
    </driver>

    How to validate a JavaEE6 Bean in a job

    Normally bean validation is already integrated in frameworks like PrimeFaces, but what if we're working on data in a batch job? In these cases we won't have access to these libraries. So how do we validate our bean? Here's how I did it.

    For example we have an entity bean Customer:
    @Entity
    @Table(name = "CUSTOMER")
    public class Customer implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;

    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "FIRST_NAME")
    private String firstName;

    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "LAST_NAME")
    private String lastName;

    }

    To validate we need to inject the bean Validate and validate our bean, here's how:
    import javax.validation.ConstraintViolation;
    import javax.validation.ConstraintViolationException;
    import javax.validation.Validator;

    @Stateless
    public class CustomerImport {

    @Inject
    private Validator validator;

    private void validate(Customer customer) {
    Set<ConstraintViolation<Customer>> violations = validator.validate(customer);

    if (!violations.isEmpty()) {
    throw new ConstraintViolationException(
    new HashSet<ConstraintViolation<?>>(violations));
    }
    }

    }

    Haster å få på plass gjeldsregister



    Stadig flere klarer ikke å betale forbruksgjelden sin. Mange betaler gammel gjeld med ny gjeld. Tiden er overmoden for et gjeldsregister for forbruksgjeld. Stortinget bør vedta forslaget om gjeldsregister fra Stoltenberg-regjeringen så raskt som mulig.
     
    Både antall inkassosaker og søknader om offentlig gjeldsordning har økt med mer enn 50 % siden før finanskrisen. I følge SIFO rapporterte seks prosent av de spurte at de hadde tilbakevendende betalingsproblemer i 2012.  Ti prosent var svært bekymret for kredittkortgjelden. To prosent hadde fem eller flere kredittkort. 

    Det er altså en betydelig andel av befolkningen som har store problemer med forbruksgjeld, og tendensen er økende. En kortstokk med kredittkort er ofte et tegn på en farlig vane der gammel gjeld betales med ny. Tallene viser at det kan være opptil hundre tusen nordmenn som bruker kredittkort til å betale kredittkortgjeld. 

    Forbruksgjeld er dyr. Rentene er skyhøye. Å holde kreditorene borte med stadig nye kort er derfor en sikker vei mot økonomisk katastrofe. Den eneste eksterne begrensningen på en slik eskalerende kortgjeld er i dag antall kredittkorttilbydere i Norge. Bankene er nå helt avhengig av opplysningene som kunden gir. Et sentralt gjeldsregister er ulovlig i Norge. 

    Så lenge låntakeren klarer å unngå betalingsanmerkning, vil han dermed uten store problemer kunne fortsette å ta opp stadig større forbruksgjeld. Det er selvsagt låntakers ansvar å gi korrekte opplysninger til banken, men en kan ikke forvente det av en som kjemper en håpløs og desperat kamp mot kredittkortrentene.

    Det er derfor på høy tid med et gjeldsregister. Den forrige regjeringen har hatt saken ute på høring, og rakk så vidt å legge frem et forslag før den gikk av. Det foreslås her at forbrukslån uten pantesikkerhet også skal registreres i Løsøreregisteret. Forslaget omfatter altså ikke boliglån og billån der banken har sikkerhet, ettersom disse opplysningene i dag kan hentes fra de eksisterende panteregistrene. 

    Forslaget er godt. Det er ingen grunn til å ta nye runder her. Det finnes noen kritiske røster, men argumentene mot et slikt register er lite overbevisende. Den kanskje fremste motstanderen mot et gjeldsregister er Datatilsynet. De mener at problemet med forbruksgjeld er forlite til å fortjene et register. SIFOs tall tyder imidlertid på det motsatte. 

    Det er jo også slik at panteregistrene allerede registrer all pantesikret gjeld. Konsekvensen for personvernet av å inkludere forbruksgjeld synes derfor ganske begrenset. 

    Fra den andre siden kommer det også kritikk på at forslaget ikke er omfattende nok. Forbrukerrådet mener blant annet at med et slikt register burde det også følge et pålegg til bankene om å bruke det. Dette bygger på erfaringer fra Sverige, hvor enkelte kredittyterne ikke slår opp i registeret. 

    Et slikt påbud om bruk er unødvendig. Antakeligvis finnes det en naturlig forklaring på at kredittinstitusjoner ikke alltid slår opp i registret. Kredittytere som ikke slår opp når de burde gjøre det, vil motta alle de dårlige kundene som ikke får lån andre steder. Bunnlinjen vil nok derfor ganske raskt overbevise långiveren om å bruke registeret når det er nødvendig. 

    Et gjeldsregister vil også skyve mer av ansvaret over på de profesjonelle kredittinstitusjonene. Når informasjon om alt for høy gjeld er tilgjengelig, vil det antakeligvis være brudd på frarådingsplikten dersom lån likevel innvilges. Det vil trolig være av liten betydning om banken faktisk har slått opp i registeret. I dag kan banken skylde på feilaktige opplysninger i lånesøknaden. Med et gjeldregister forsvinner denne muligheten. Dette vil stille låntaker sterkere i senere gjeldsforhandlinger. 

    En annen stor fordel med denne loven er at långivers risiko reduseres betydelig, noe som vil senke renten for de som får lån. I dag vet ikke banken om kredittkunden har en uhåndterlig forbruksgjeld eller ikke. Banken må derfor ta en saftig rente for å dekke tapene på de dårlige kundene. Med et offentlig gjeldsregister kan banken identifisere dårlige kunder på forhånd, og det vil gi lavere rente for alle andre.


     

    Employment slumps in Canada and the U.S.

    Some time ago I wrote about the prospect of the U.S. economy going through a Canadian-style slump (see here). To summarize: The recession that hit Canada and the U.S. in the early 1990s was much more severe in Canada than in the U.S., and the recovery in Canada took almost a decade to complete. In 2008, the tables appear turned. In what follows, I plot the employment-to-population ratio for Canada from 1989:1 - 2003:1 and match it up against the same ratio for the U.S. beginning in 2007:1 - present. The parallels thus far are striking.

    Let's start with the employment ratios (courtesy of my able research assistant, Li Li) for the whole population in both countries: (All starting points normalized to 100 -- the actual employment rates are close in any case.)

    This shows that the slump, as measured by the drop in employment, was about the same magnitude for Canada in 1990-91 as for the United States in 2008-09. The recovery dynamic in both cases appears to be painfully slow.

    Let's now decompose employment across various age groups.





    In terms of young and prime-age workers, the U.S. looks a little more depressed relative to the Canadian experience. The experience of older U.S. workers seems less depressed (but the behavior of older workers since the mid 1990s is influenced by a change in secular dynamics, so perhaps should not be viewed as a recovery dynamic.)

    Now let's decompose by age and sex. Here we have the data for adult men:


    And here we have the age-sex decomposition for men:






    The correspondence between those aged 20-55 (the bulk of the population) is very close. Here is the data for adult females:


    And here is the age-sex decomposition for women:






    The most recent U.S. recession is sometimes labeled a "mancession" in reference to the fact that men appear to have been particularly hard hit (my colleague Silvio Contessi and my RA Li Li talk a bit about this phenomenon here.) It is interesting to note that while this may have been the case, the data here suggest that U.S. females were nevertheless hit harder than their Canadian counterparts in the 1990s.

    Just for fun, I asked Li Li to plot broad stock market indices: the TSX composite index for Canada and the S&P 500 for the U.S. (both series have been adjusted for inflation).


    Anyone willing to bet against the EMH?

    At this point, I'm not entirely sure how to interpret this data. My feeling is that something useful may come out of studying the Canadian episode in greater detail. Maybe a few Ph.D. students are willing to take up the challenge?

     

    Employment Gaps

    Is the level of employment in the U.S. currently too low? To many people, the answer to this question seems obvious: of course it's too low, you moron.

    But "too low" relative to what? Relative to historic averages? Employment seems low relative to recent history, but high relative to more distant history; see here. Moreover, secular employment dynamics across demographic groups often move in different directions, making the question even more difficult to answer. (Marcela Williams and I talk at length about the "many moving parts" of the labor market here.)

    Maybe we can learn something by comparing the U.S. experience with Canada. As far as different countries go, Canada is about as "close" to U.S. as one can get. Moreover, as I've pointed out before, the Canadian economy experienced a great slump in the 1990s, a phenomenon that appears to be playing out now in the U.S.

    Let me start by looking at the employment-to-population ratios across these two countries. (In Canada, the population constitutes those aged 15+, in the U.S., those aged 16+). Here is what the picture looks like for prime-age males:


    Employment is similar early in the sample, but a gap emerges in the 1980s, growing even larger during the "great Canadian slump" of the 1990s. But for most of the 2000s, up to 2008, the employment gap appears to have vanished. Since 2008, the employment gap has reversed itself: the employment rate among prime-age American males is now significantly lower (2 percentage points) than their counterparts in Canada for the first time in about 40 years.

    Can we use these employment gaps to infer something about the slowness of the U.S. recovery? I'm not sure. Well, we have to be careful. But this picture might make one more sympathetic to the idea that there is an "output gap" in the U.S. that's at least as large as the value-added associated with increasing prime-age male employment by 2 percentage points. (Of course, this says nothing about what the source of the gap is.)

    What does this data look like for other age groupings? Let's take a look. Here's the picture for "adult" teens:


    A lot of this employment must be in the form of part time work. The employment ratios are low relative to other demographic groups, as one would expect, but the two countries are quite similar here until about 2000. What happened?

    Here we have young adult men:


    The picture here looks similar to the one for prime-age males. Together, the two pictures above show that the recent recession hit younger men in the U.S. harder than their counterparts in Canada, and also relative to older men in general.

    As for older men:


    Evidently, older men are immune from negative aggregate demand shocks. Interesting.

    Let me now report what the same data looks like for females. For prime-age females, the picture is this:


    For most of the sample, the employment ratios track each other fairly closely, with the Canadian ratio slightly below its American counterpart. Again, as with teenage men, something appears to have happened in 2000. The female employment rate appears to be in secular decline while, in Canada, it has remained elevated and stable. What are the implications of this recent divergence? And how should it be evaluated by policymakers? We need more data to answer these questions.

    Here's the picture for teenage women. Again, a large cross-country gap emerges around 2000.


    It is interesting to note that the upward trend in female employment is absent in this age category. It is also less apparent in young women:


    But once again we see a significant divergence across these two countries beginning at around 2000. The recession in 2008 served to enlarge these differences.

    Finally, for older women:


    As with older men, older women seem largely impervious to the business cycle.

    What is it that is leading older people to devote more time to market work -- seemingly at the expense of younger people? It is tempting to argue that the financial crisis, by wiping out retirement portfolios, compelled older people to work more to rebuild their lost wealth. But the trends here appear to have been in place since before 2000.