読者です 読者をやめる 読者になる 読者になる

Fight the Future

何かを始めたら、半分成功したのと同じ

what is JSRs in 900s

java

Now max JSR number is 380, but JSR has 900s number. For example, JSR 901 is "JavaTM Language Specification".

The Java Community Process(SM) Program - JSRs: Java Specification Requests - List of all JSRs

What are these? They are completed and moved to maintaining.

How to get an application class loader in Java Agent method

java jvm

In Java Agent method, such as premain() or agentmain(), class loader is system classloader, not application class loader.

If you intent to change bytecode of class loaded by application class loader, you will need an application class loader.

To get this, I think there is only one way. Get from Instrument API, as shown below.

public static void agentmain(String agentArgs, Instrumentation inst) throws Exception {
  Class[] classArray = inst.getAllLoadedClasses();
}

getAllLoadedClasses() returns an array of all classes currently loaded by the JVM. So, we need to seek the application class loader from these.

Map<String, Class> classMap = Arrays
                .stream(
                   inst
                     .getAllLoadedClasses()
                )
                .collect(
                  Collectors
                    .toMap(
                      c -> c.getName(), c -> c, (c1, c2) -> c1
                    )
                );

String target = "com.example.HelloWorld";
ClassLoader classLoader = classMap.get(target).getClassLoader();

It works well, but Agent class need to know the application class name. Is this okay?

material of my session in JJUG CCC 2016 fall

java jvm コミュニティ

I talked about Java Agent and bytecode manipulation libraries in JJUG CCC 2016 fall.

My session room was filled to capacity with bytecode fans!

This is a material of this session.

www.slideshare.net

How can I get a web application classloader in Java Agent's method agentmain()

java jvm

I implement Java Agent which transform classes of a web application running in an application server.

To do so, I need a web application classloader which load these classes.

I know Instrument#getAllLoadedClasses() method.

But this method returns Class array, so I retrieve the Class loaded by web application class loader by Class name etc.

I think this is not good code.

Is there another way to get a web application classloader in Java Agent?

Use @GetMapping, @PostMapping in Spring 4.3 or later

Spring java

I always use @RequestMapping in Controller.

@Controller
public class TestController {
    @RequestMapping(value = "test", method = RequestMethod.GET)
    public String index() {

But in Spring 4.3, @GetMapping and @PostMappiing are provided. I was not sure about that.

So we don't need to write such a long statement. Just write below:

@Controller
public class TestController {
    @GetMapping("test")
    public String index() {

My proposal has been approved in Devoxx US 2017

java コミュニティ

My proposal has been approved in Devoxx US 2017. I have a Quickie session.

Session title is "Web app that has one billion face images and Japanese "kawaii" culture". This is about an application which I have been developed, including not only technical term, but also Japanese culture.

CfPを通過し、Devoxx US 2017でQuickieセッションをすることになりました!

セッションタイトルは"Web app that has one billion face images and Japanese "kawaii" culture"です。 私が開発しているアプリケーションについてですが、技術的要素だけでなく、日本の文化についても話す予定です。

cfp.devoxx.us

Java SE 9 will be released at 2017/07/29

java

At now(2016/11/19), Java SE 9 will be released at 2017/07/29.

2016/11/19時点では、Java SE 9は2017/07/29にリリース予定です。