GithubHelp home page GithubHelp logo

Comments (2)

skeeto avatar skeeto commented on July 17, 2024

I'm sorry, it looks like at some point I broke the hotswap demo. This should be fixed by 1f633b4. It works for me with both OpenJDK 1.6.0_27 and 1.7.0_25.

With hotswap when a method is updated it's only used next time the method called. If the original method is already on the stack or otherwise in use, it will continue to run unchanged (i.e. the original version finishes its course). The problem was that the "Hello, %s" string was being printed in a loop within the same method. When the run() method was replaced by hotswap, the new version of the method was never actually run because it was never invoked. Instead just the old loop continued to execute. I moved the print statement out into its own method, sayHello(). When a new version is hotswapped, it will be invoked next time around the loop.

Ad for october-chess-engine, keep in mind that hotswapping has all sorts of caveats. You can't change any class or method signatures, but also it's finicky about constants. For example, in BoardPanel.java, you could try to change the constants DARK and LIGHT and hotswap, but it probably won't work. I think the JVM inlines these or something. Instead, change the paintComponent() method where these constants are being used (lines 217 and 219). After you hotswap you also need to force a redraw, which you can do by clicking anywhere on the chess board in the GUI, or by having the computer play itself while you hotswap.

if ((x + y) % 2 == 0) {
    g.setColor(Color.WHITE);
} else {
    g.setColor(Color.BLACK);
}

If you hotswap the above and click the board, you should see the board go from the default brown shades to straight black and white.

from sample-java-project.

ameyp avatar ameyp commented on July 17, 2024

Thanks. In retrospect it makes sense that someone would have to call the modified function for the changes to be reflected, don't know why that didn't occur to me. And the chess engine also works when I click on the board, I just assumed that the redraw would happen every second or so, based on your blog post. And now I realize that I had forgotten to checkout the hotswap-demo branch.

Thanks for your help!

from sample-java-project.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.