Synchronized Block on Grails Works on Windows But No in Linux

synchronized block on grails works on windows but no in linux

You are right about why you're getting the StaleObjectStateException.

If what you're looking for is pessimistic locking (allowing only one transaction access to the data at any given time), then you can use the domain class lock() method:

class TestService {
static transactional = true

TesteSync incrementa() {
TesteSync t = TesteSync.lock(1)
t.contador++
return t.save()
}
}

You can learn more about Grails pessimistic locking here.

PS: Grails services are transactional by default. But in my example I explicitly made the service transactional to call something to your attention: The lock is released by Grails automatically when the transaction commits. I also removed the flush because the data gets flushed when the transaction commits. If you were doing this from a controller method that's not explicitly set to @Transactional, then you would need the flush.

TIP: When you query by ID you can do this...

SomeDomainClass.get(1)

...instead of this...

SomeDomainClass.findById(1)

Grails Java 8 dev-mode Support

My advice, simple, load and clear: migrate (or upgrade really), and don't look back.

The Why.
We started a GG project in Oct 2014 with Grails 2.3 and JDK7, and went all the way up to 2.5.1 and Java 8. Then we started seeing the grounds shift under our feet with Grails 3 and Gradle out there while we stagnated. Grails 3.1, .2, .3, .4, .5... while we stood behind glass looking. Stackoverflow was buzzing with the new features and problems while water streams were getting thinner and drier on Grails 2. It hurt and I think you must be going through this now.

The How.
Your biggest (if not and only) problem is what you got into your BuildConfig file - the plugins. Almost everything else you can follow blindly in this decent Upgrade page but the BuildConfig.groovy to build.gradle step. For example, plugins that dealt with spring security and web services had to be changed, and if you have embedded ajax components (like submitToRemote and remoteFunction) in your views, then you need to think about rebuilding all those in pure jQuery and ajax calls or just add the ajax plugin for all such components to work as they did.

The Steps.

  1. Get to know Gradle a little bit and depend heavily on sdkman
  2. IntelliJ 15 for an IDE
  3. Create a Grails 3 project
  4. If spring security is one of your plugins, don't copy code from your older project, incorporate the plugin mechanics locally using quickstart
  5. For your older ajax UI components, you could add the following line to your build.gradle and all should work as they did, although the GG team advises against that. compile 'org.grails.plugins:ajax-tags:1.0.0.RC1'
  6. Web services used? Follow the steps in this post to see how you should craft the plugin inclusion as well as using the services
  7. Yes, now follow the steps in the upgrade page mentioned above, but
    keep an eye on each and every plugin. The supported ones are in this page.

Others vital steps? Add as comments or straight to this list to make such a task easier and easier for the G2'ers out there. I will keep editing this.

Grails 2.3.0 Auto-reloading not working

It seems that in Grails 2.3 the reloading is no longer the default

In Grails 2.3 the reloading agent is no longer on the build system
path unless you pass the -reloading flag to the grails command:

grails -reloading run-app

However, you can enable forking in your buildConfig using the following configuration:

forkConfig = [maxMemory: 1024, minMemory: 64, debug: false, maxPerm: 256] 
grails.project.fork = [
test: forkConfig, // configure settings for the test-app JVM
run: forkConfig, // configure settings for the run-app JVM
war: forkConfig, // configure settings for the run-war JVM
console: forkConfig // configure settings for the Swing console JVM ]

More information : Forked Execution and the Reloading Agent

Different results when running java awt code on Windows and Linux

Your method is based on getFontMetrics(), that return the font metric of the current font. I assume you're using default font in your program, and they are different in the different OS, so the result height might be different.

Grails Dependencies not Added as Libraries to IntelliJ IDEA

Understanding how Grails resolves Gant scripts really helps:

http://grails.github.io/grails-doc/2.3.x/guide/commandLine.html

Grails searches in the following directories for Gant scripts to execute:

  • USER_HOME/.grails/scripts
  • PROJECT_HOME/scripts
  • PROJECT_HOME/plugins/*/scripts
  • GRAILS_HOME/scripts

The problem seems that IntelliJ IDEA is automagically providing this Gant script, but putting the script in the wrong spot.

Using VisualVM, here are the user directories:

user.dir=C:\Users\%USERNAME%
user.home=\\SOME\network\drive\%USERNAME%

So even though Cygwin, and so it seems IntelliJ IDEA, treats C:\Users\%USERNAME% as the home directory, the Windows Group Policy maps it to a network share and Java uses this value as user.home.

Looking in C:\Users\%USERNAME%\.grails\scripts, I was able to find the script. I copied it to \\SOME\network\drive\%USERNAME%\.grails\scripts and then Grails recognized the script and IntelliJ IDEA was able to configure itself properly.



Related Topics



Leave a reply



Submit