groovy

Lock contention in Groovy Shell interpreter under high load

隐身守侯 提交于 2021-01-05 09:33:52
问题 We are evaluating GroovyShell interpreter (v2.4) in our application for dynamically executing standard Java syntax. Earlier, we were using Java BeanShell Interpreter for it, but it has an issue under high load which prompted us to look for an alternative such as Groovy. Sample Java Code static String script = "int y = x * x; System.out.println(\"** value of y ** :: \" + y ); "; GroovyShell gs = new GroovyShell(); Script evalScript = gs.parse("void evalMethod() {" + script + "}"); // bind

Groovy regex/pattern matching

别来无恙 提交于 2021-01-05 09:26:13
问题 How do we do regex matching in groovy, what will be the regex in groovy for below example? Example : f2376 Regex: (anyLetter)(followed by 4 digits) 回答1: Pretty simple with groovy "f1234" ==~ /[a-z]\d{4}/ Note that the regex [a-z]\d{4} means any of the characters a-z once, followed by exactly 4 digits, and can be probably be used with any language that handles regex, not just groovy. In my console I tested for just lower case letters, but to handle upper case too just do "f1234" ==~ /[a-zA-Z]

Groovy regex/pattern matching

感情迁移 提交于 2021-01-05 09:24:05
问题 How do we do regex matching in groovy, what will be the regex in groovy for below example? Example : f2376 Regex: (anyLetter)(followed by 4 digits) 回答1: Pretty simple with groovy "f1234" ==~ /[a-z]\d{4}/ Note that the regex [a-z]\d{4} means any of the characters a-z once, followed by exactly 4 digits, and can be probably be used with any language that handles regex, not just groovy. In my console I tested for just lower case letters, but to handle upper case too just do "f1234" ==~ /[a-zA-Z]

How in groovy (java) automatically find out the json field type and return values from json, replacing null with empty space?

筅森魡賤 提交于 2021-01-05 09:13:43
问题 The question is still relevant! In my task, json comes to my input, which I do not know in advance. I need to collect all json field types into "types" and return all values ​​using reader.outputLines . Now the list of json field types is formed like this: def types = list.find (). Values ​​() *. GetClass () *. SimpleName But I am faced with a problem when the same field in the first json block is null, and in the second the integer and the type is defined as null, and not as Integer. How to

How in groovy (java) automatically find out the json field type and return values from json, replacing null with empty space?

£可爱£侵袭症+ 提交于 2021-01-05 09:12:00
问题 The question is still relevant! In my task, json comes to my input, which I do not know in advance. I need to collect all json field types into "types" and return all values ​​using reader.outputLines . Now the list of json field types is formed like this: def types = list.find (). Values ​​() *. GetClass () *. SimpleName But I am faced with a problem when the same field in the first json block is null, and in the second the integer and the type is defined as null, and not as Integer. How to

改造工程步骤

非 Y 不嫁゛ 提交于 2021-01-05 04:05:27
背景: 对于存在有问题的项目(包括 代码不规范 数据库表命名不规范 )需要改造 系统业务架构: 步骤: 1 新建工程 : 将需要改造的项目拷贝一份 修改项目名称 2 将相应的表结构拷贝到新的数据库中 修改不直观的表名 字段的备注等 3 修改对应的代码 和数据库表字段对应 熟悉接口对应的相关类 找到与之相关的 注意: 1 并发幂等性(重试引起)控制 2 方法设置开关 3 金额存整数(元化为分) 4 解耦 (rocketMQ消息异步解耦) 加入状态机【待完成】 5 分库【垂直拆分 基本的思路就是按照业务模块来划分出不同的数据库】 分表【垂直拆分某个表中的字段比较多,可以新建立一张“扩展表”,将不经常使用或者长度较大的字段拆分出去放到“扩展表”中】 好处: 便于 管理、维护、监控、扩展 , 在高并发场景下,垂直分库一定程度上能够突破IO 、连接数及单机硬件资源的瓶颈,是大型分布式系统中优化数据库架构的重要手段。 注意:需要改写以前的查询语句【跨库join,分布式事务等】 跨库Join的几种解决思路 1 全局表【很少发生编号 像数据字典】 系统中所有模块都可能会依赖到的一些表,将这类表在其他每个数据库中均保存一份 2 字段冗余 【最复杂的还是数据一致性问题,这点很难保证】 3 数据同步 定时A库中的tab_a表和B库中tbl_b有关联,可以定时将指定的表做同步,通过ETL工具来实施 4

Spock mock private variable

烈酒焚心 提交于 2021-01-03 09:54:22
问题 I'm wondering how I can mock some private variable in a class with Groovy/Spock. Let's say we have this code: public class Car { private Engine engine; public void drive(){ System.out.println("test"); if (engine.isState()) { // Do something } else { // Do something } } } In Mockito I can write: @Mock private Engine engine; @InjectMocks private Car car = new Car(); @Test public void drive() { when(engine.isState()).thenReturn(true); car.drive(); } But I don't know how to do the same in Spock.

Reload class in Groovy

落花浮王杯 提交于 2021-01-03 06:47:27
问题 I have a custom ClassLoader extending GroovyClassLoader which compiles the source code to .class files on disk and then loads the resulting class: class MyClassLoader extends GroovyClassLoader { File cache = new File( './cache' ) Compiler compiler MyClassLoader() { CompilerConfiguration cc = new CompilerConfiguration( targetDirectory:cache ) compiler = new Compiler( cc ) addClasspath cache.path } @Override Class findClass( name ) { try{ parent.findClass name }catch( ClassNotFoundException e )

grails 4 groovy's date enhancement methods missing

只愿长相守 提交于 2021-01-03 05:25:37
问题 In a previous version of grails I was able to use the groovy enhanced version of java.util.Date found here here. After upgrading to grails 4, all those methods throw no signature of method on java.util.Date. Somehow the groovy additions aren't being picked up. def fdate=new Date(); out << fdate.format("MM/dd/yyyy") //No signature of method: java.util.Date.format() 回答1: Add a dependency to groovy-dateutil to your build.gradle : runtime 'org.codehaus.groovy:groovy-dateutil' The relevant

grails 4 groovy's date enhancement methods missing

假装没事ソ 提交于 2021-01-03 05:22:40
问题 In a previous version of grails I was able to use the groovy enhanced version of java.util.Date found here here. After upgrading to grails 4, all those methods throw no signature of method on java.util.Date. Somehow the groovy additions aren't being picked up. def fdate=new Date(); out << fdate.format("MM/dd/yyyy") //No signature of method: java.util.Date.format() 回答1: Add a dependency to groovy-dateutil to your build.gradle : runtime 'org.codehaus.groovy:groovy-dateutil' The relevant