`
agile_boy
  • 浏览: 548139 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

【翻译】Graeme答复:Groovy and JRuby: Enterprise-Ready?

阅读更多
    有博客报道说Groovy并不适合企业,其目的只是在散播FUD(Fear, Uncertainty, Doubt)而已. 此报道如下:
  http://www.huxili.com/index.php?cat=reports&id=ID000188
    此报道以"Groovy and JRuby: Enterprise-Ready?"为题且得出结论是:Groovy还不适合企业仅仅是因为内存泄漏。某些人并不懂语言间习惯用法差异,而简单地放在一起进行对比,当然是无稽之谈了。
    此报道并没有提供任何示例代码,更多的是通过怀疑的方式来验证其正确性,尽管如此报道还是陈述了Groovy运行在以下一些步骤的时候,会导致内存溢出:
  1. Call shell.evaluate("x = 100")
  2. Call System.gc()
  3. Thread.sleep(1000)
  4. Record used memory
  5. Repeating (1-4)

    我要猜一下他们可能用到的Groovy代码,我敢打赌这些代码应该象下面所示那样:
shell = new GroovyShell()
while(true) {
  shell.evaluate("x = 100")
  sleep(2000)
  System.gc()
}

    那么这段代码有什么问题呢?并且是怎样导致内存泄漏呢?答案很简单:每一个GroovyShell实例都有一个内部的类加载器(class
loader),而Groovy一门编译类型的语言,即便是示例中很少的一段脚本都将会被编译成类因此随着时间的流逝,类加载器将会变得越来越大。那么该
如何解决呢?请看如下代码:
while(true) {
  new GroovyShell().evaluate("x = 100")
  sleep(2000)
}

    这么做,JVM就会自动回收不再使用的GroovyShell (当然包括它的类加载器)了,加载器都被回收了,其旗下的类当然也自然被回收了。JRuby当然不存在这样的问题,因为其本身就是解释性语言。没有相关语言的习惯用法,而仅仅凭借4行脚本代码,就断定一门语言是否适合企业应用,实在是滑稽可笑!所以要提防那些未经你自己证实的所谓的官方展望报告吧!


    至此翻译已经完毕,可是所谓的报道,本人也觉得的很可笑,不过从Graeme的答复中,本人也受益匪浅,也了解到自己对Groovy掌握还是比较肤浅的,继续努力[img]../../../images/smiles/icon_biggrin.gif" alt="[/img]
    其实从报道中也可以看到Groovy正在快速的发展,当然发展过程中不可能避免的有流言蜚语,同时也说明Groovy在备受关注中。
    最后,有几个有意思的链接与大家共享一下
5
0
分享到:
评论
13 楼 bnmcvzx 2008-05-03  
引用

shell = new GroovyShell()
while(true) {
  shell.evaluate("x = 100")
  sleep(2000)
  System.gc()
}


照这样的例子java中也不会这样写的呀
12 楼 bnmcvzx 2008-05-03  
引用

<br /><pre name="code" class="java">shell = new GroovyShell()
while(true) {
  shell.evaluate("x = 100")
  sleep(2000)
  System.gc()
}
</pre>
11 楼 geszJava 2008-01-24  
找一下x:\Program Files\Macromedia\Dreamweaver 8\Configuration\DocumentTypes目录下面的MMDocumentTypes.xml文件,查找一下documenttype id="JSP",把gsp也给添加上.不过taglib是不支持的.这样只是凑合能用,完美得应该是楼主说的那样吧.
10 楼 agile_boy 2008-01-23  
to winter  :
  very cool!!thanks
9 楼 winter 2008-01-22  
引用
但是view的gsp文件无法在dreamweaver中可视化编辑,手工写views太低效了!grails还有太长的路走!


看这里 Using GroovyServer Pages in Dreamweaver

引用
We started using Grails in our current project for one of the internal web-applications. Grails uses GroovyServer Pages (gsp) for web pages and layout templates (you can also use JSP instead). As I don’t like to use Eclipse for web-design tasks, I figured out how to add gsp support to Dreamweaver (CS3).

Step 1: Add .gsp file extension
Edit the Extensions.txt file, which can be found here:
Windows: \Documents and Settings\username\Application Data\Adobe\Dreamweaver 9\Configuration
Mac OS X: /Users/username/Library/Application Support/Adobe/Dreamweaver 9/Configuration
Add a new line with GSP:Groovy Server Pages and add the gsp extension to the first line. Restart Dreamweaver, which will now recognize the .gsp files and open them in the editor.
Next, add the following code to configuration/DocumentTypes/MMDocumentTypes.xml

<documenttype id="GSP" internaltype="Dynamic" winfileextension="gsp" macfileextension="gsp" file="Default.gsp" writebyteordermark="false">
<TITLE>
<MMString:loadString id="mmdocumenttypes_70" />
</TITLE>
<description>
<MMString:loadString id="mmdocumenttypes_71" />
</description>
<dtdcontext>html</dtdcontext>
</documenttype>


Adjust the id values if necessary. In the folder NewDocuments create a Default.gsp file. Gsp files are not being shown as option in the new files dialog yet, so the Default file is not being used. If someone knows how to do this, please let me know.
It takes adobe a couple of pages to explain it all in detail: http://www.adobe.com/go/16410

Step 2: Add the gsp tag library
Download the GspTagLibrary for Dreamweaver, unpack it and copy the gsp folder to the TagLibraries folder within the configuration folder. Add the text of gspTagLibrary.vtm to the existing TagLibraries.vtm file.

Step 3: Enable code coloring
Open CodeColoring.xml (Configuration/CodeColering) in an editor and add gsp to the doctypes attribute of the entries for Html, JavaScript and CSS. Restart Dreamweaver.

Next step could be to add a special color schema for gsp tags and groovy when using scriptlets and maybe one day I will have time to learn how to write Dreamweaver Extensions, which would hopefully make it possible to do all of this automatically.


8 楼 winter 2008-01-22  
要是非得在DW编辑,把gsp临时改成jsp。。。。。。。
7 楼 魔力猫咪 2008-01-22  
最近正在看Grails。书是从网上下来的,虽然旧了点,但还是很不错的。用Grails快速开发好舒服。
6 楼 lordhong 2008-01-22  
我喜欢groovy,2008年喜欢可以多多用上
5 楼 murainwood 2008-01-22  
   Grails,半敏不捷
4 楼 agile_boy 2008-01-21  
qieren 写道
groovy in action还会有中文版吗?...英语太烂...都等了好久了

如果此Groovy in Action中文版公告准确的话,应该快了。
让我们期待吧,你如果有什么因为可以到GoG的圈子里提问。
3 楼 qieren 2008-01-21  
groovy in action还会有中文版吗?...英语太烂...都等了好久了
2 楼 agile_boy 2008-01-21  
gsp跟jsp是一脉相通的,如果喜欢拖拽,可以尝试JSF啊
1 楼 ourfirebird 2008-01-21  
但是view的gsp文件无法在dreamweaver中可视化编辑,手工写views太低效了!grails还有太长的路走!

相关推荐

Global site tag (gtag.js) - Google Analytics