根据:
http://www.ibm.com/developerworks/library/j-jtp03304/
在新的内存模型下,当线程A写入易失性变量V,并且线程B从V读取时,在写入V时对A可见的任何变量值现在都保证对B可见.
互联网上的许多地方声明以下代码永远不应该打印"错误":
public class Test {
volatile static private int a;
static private int b;
public static void main(String [] args) throws Exception {
for (int i = 0; i < 100; i++) {
new Thread() {
@Override
public void run() {
int tt = b; // makes the jvm cache the value of b
while (a==0) {
}
if (b == 0) {
System.out.println("error");
}
}
}.start();
}
b = 1;
a = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
b …
我想将我的css按钮设置为unlickable/disable.我有一个表格,当我点击"发送"按钮后,我想设置此按钮禁用/无法点击.任何人都可以帮助我?
这是我的按钮:
.good-form > .actions a,
.theButton {
display: inline-block;
width: 540px;
margin: 20px 0 10px;
padding: 12px;
background-color: #b6adb4;
border-radius: 2px;
border: 0px;
text-align: center;
color: #fff !important;
text-decoration: none !important;
font-size: 16px;
font-family: 'Rubik', sans-serif;
}
Run Code Online (Sandbox Code Playgroud)
这是我的jquery:
首先我试过这个:不工作!
$(".good-form > .actions a, .theButton").attr('disabled','disabled');
Run Code Online (Sandbox Code Playgroud)
我试过这个:不工作
$(".good-form > .actions a, .theButton").addClass('disabled');
Run Code Online (Sandbox Code Playgroud)
要么
$(".good-form > .actions a, .theButton").addClass("disabled");
Run Code Online (Sandbox Code Playgroud)
感谢谢谢!
我h2仅将内存数据库用于测试目的.似乎是默认端口8082,这导致我的测试在heroku上失败.
我想更改此端口号.我怎样才能做到这一点 ?
到目前为止我做了什么:
我的本地机器($USER_HOME/.h2.server.properties)上似乎有一个文件指定了这个端口.更不用说将这个文件放在应用程序工作区之外是很奇怪的,我无法在heroku中检查它.
我试图设置webPort,port在application-test.properties(它是一个属性文件我用我的测试),但它没有工作(我尝试不同的组合server.port,`spring.data.source.h2.webPort等)
application-test.properties
spring.datasource.url=jdbc:h2:mem:tesdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
Run Code Online (Sandbox Code Playgroud)
的build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
}
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
test{
forkEvery = 1
testLogging {
showStandardStreams = true
}
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies { …Run Code Online (Sandbox Code Playgroud) 我想将一些 JVM 参数传递给我的 Gradle bootRun 任务,即-Xbootclasspath. 我已经添加了:
bootRun {
systemProperties = System.properties
}
Run Code Online (Sandbox Code Playgroud)
到我的build.gradle文件,但当我运行时它不喜欢它:
gw bootRun -Xbootclasspath/p:....
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Unknown command-line option '-X'.
Run Code Online (Sandbox Code Playgroud)
我是否可能错误地运行了这个,或者System.properties不是我正在寻找的正确方法?
我正在阅读我在这个短语中遇到的java语言编程中的"数据抽象":
java中的对象具有三个基本属性:状态,身份和行为.对象的状态是其数据类型的值.对象的标识将一个对象与另一个对象区分开来.将对象的标识视为其值存储在内存中的位置很有用.
每个人都可以更具体地解释什么是身份?
我想知道如何向下滚动以使用appium和java单击Android中的元素?
我在" android.support.v7.widget.RecyclerView"中有一个元素列表.由于它有10个以上的元素,我们需要滑动屏幕才能看到下面的元素.每个元素都具有相同的id,即" com.osanda.exampleapp/textViewTitle".但他们的文字不同,如"Apple","Orange","Grapes"......
我只需要滚动并使用其文本("Apple","Orange","Grapes".....)点击相关元素.
我已经遵循了许多教程,但无法正确完成.我设法向下滚动屏幕.但是当元素位于滚动的中间位置时它将不起作用.
当我列出元素名称时,它只显示可见元素,而不是所有元素.
List<WebElement> elements = androidDriver.findElementByClassName("android.support.v7.widget.RecyclerView").findElements(By.id("com.osanda.exampleapp:id/textViewTitle"));
for(WebElement element : elements) {
System.out.println(element.getText());
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我遇到了以下问题.我正在使用的Weld实现CDI.
我发现如果服务注释了,@ApplicationScoped那么@PostConstruct在第一次使用服务之前不会调用section.这是一个重现此行为的代码:
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.CDI;
public class TestCdi {
public static void main(String[] args) {
try (WeldContainer weldContainer = new Weld().containerId("test").initialize()) {
FooService fooService = CDI.current().select(FooService.class).get();
fooService.test();
System.out.println("Done");
}
}
@ApplicationScoped
public static class FooService {
@PostConstruct
public void init() {
System.out.println("Post construct");
}
public void test() {
System.out.println("test");
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果fooService.test();被注释,则FooService.init()不会被调用.但删除@ApplicationScoped它再次工作!
这对我来说似乎很奇怪,我无法找到和描述这种行为.
此外,规范javax.inject.Provider.get()说:
提供完全构造和注入的T实例.
那么,问题是什么?它是这样设计还是这个bug?对我来说更重要的是:如何绕过这个问题?我需要我的服务 …
我正在编写一个逐行读取文件的代码,只返回以下行,例如:
int int0 =( - 953);
int int1 =(-411);
int int2 = 5471;
int int3 = 823;
之后,我想只返回正面和负面的数字.为此,我写了以下内容:
String str = line.replaceAll("\\D+","");
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
运行此代码的结果是:
0953
1411
25471
3823
我寻求的输出是:
-953
-411
5471
823
我怎样才能做到这一点?
java ×6
android ×1
appium ×1
automation ×1
cdi ×1
compiler-bug ×1
concurrency ×1
css ×1
gradle ×1
h2 ×1
heroku ×1
java-ee ×1
javascript ×1
jquery ×1
jvm ×1
object ×1
oop ×1
regex ×1
scroll ×1
spring ×1
spring-boot ×1
volatile ×1
weld ×1