在我的Web应用程序中,我尝试使用Java SDK7 WatchService创建目录轮询bean.我想要实现的是在自己的线程中运行此bean,以便它不会阻止应用程序.就像是:
<bean id="directoryPoller" class="org...MyDirectoryPoller" scope="thread"/>
Run Code Online (Sandbox Code Playgroud) 我在这里玩BarCode扫描仪的原始示例:
他们可以在相机工厂内启动AutoFocus/Flash,如下所示:
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 1024)
.setRequestedFps(15.0f);
// make sure that auto focus is an available option
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
}
mCameraSource = builder
.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
.build();
Run Code Online (Sandbox Code Playgroud)
但是,cameraSource构建器上的此方法在当前版本中已消失,因此无法访问此设置.此外,我需要在使用过程中更改FlashMode,因此这也不是这样做的方法.我发现这个丑陋的解决方案来访问相机: …
有很多关于这个主题的文章:
我发现最后接受的答案特别有趣:
如果您正在使用InnoDB或任何行级事务RDBMS,则任何写入事务都可能导致死锁,即使在完全正常的情况下也是如此.较大的表,较大的写入和较长的事务块通常会增加发生死锁的可能性.在你的情况下,它可能是这些的组合.
这意味着我们永远不能阻止它们,而只能处理它们.真的吗?我想知道你是否可以防止在网上有1000人在线调用写入数据库操作的死锁.
谷歌搜索主题没有得到任何有趣的结果.我发现只有一个(http://www.coderanch.com/t/415119/ORM/databases/Deadlock-problems-Hibernate-Spring-MS):
public class RestartTransactionAdviser implements MethodInterceptor {
private static Logger log = Logger.getLogger(RestartTransactionAdviser.class);
public Object invoke(MethodInvocation invocation) throws Throwable {
return restart(invocation, 1);
}
private Object restart(MethodInvocation invocation, int attempt) throws Throwable {
Object rval = null;
try {
rval = invocation.proceed();
} catch (Exception e) {
Throwable thr = ExceptionUtils.getRootCause(e);
if (thr == null) {
throw e;
}
if (StringUtils.contains(thr.getMessage(), "deadlock") || StringUtils.contains(thr.getMessage(), "try restarting …Run Code Online (Sandbox Code Playgroud) 我正在尝试从Kotlin调用常规Java方法,如下所示:
public <T> T proxy(KClass<T> kClass) {
// unfortunately nothing like getJavaClass() exists
return (T) proxy(kClass.getJavaClass());
}
public <T> T proxy(Class<T> jClass) {
return (T) context.getBean(jClass);
}
Run Code Online (Sandbox Code Playgroud)
在Kotlin,你可以打电话.java给每个KClass.这不是这种情况,我无法从KClass中提取Java Class对象.有办法吗?
我正在尝试实现一个 Spring 安全过滤器,如下所示:
@Configuration
@EnableWebSecurity
open class OpenApiConfigurer : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.addFilter(object : FilterSecurityInterceptor() {
override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain?) {
super.doFilter(request, response, chain)
}
})
}
...
}
Run Code Online (Sandbox Code Playgroud)
我可以确认@Configuration已加载,因为configure调用了该方法并添加了过滤器。然而,该方法doFilter永远不会被调用——我可以调用任何请求,但它永远不会在其中执行任何操作。
可能有什么问题?我需要做一些特别的事情吗?
有没有像在PHP中那样在Java中使用魔术方法的方法__call?
例如:
class foo {
@Setter @Getter
int id;
@Getter
Map <String, ClassInFoo> myMap;
protected class ClassInFoo {
@Setter @Getter
String name;
}
@Setter
String defaultKey;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Project Lombok注释来获取getter和setter方法来简化代码.
让我们考虑我的地图包含由String映射的几个项目,defaultKey定义默认项目.
我想要的是能够调用foo.getName()哪个会返回默认名称foo.myMap.get(defaultKey).getName().
我不能手动编写所有getter的原因是Foo类实际上是继承了泛型,而内部类可能是不同的.
我有点需要:
function Object __call(method) {
if (exist_method(this.method)
return this.method();
else
return this.myMap.get(defaultKey).method();
}
Run Code Online (Sandbox Code Playgroud)
这在Java中是否可行?
编辑:
我做了一个更精确的例子,说明我想在这里实现的目标:https://gist.github.com/1864457
这样做的唯一原因是"简写"内部类中的方法.
我在我的OSX 10.7.5上运行与Debian的并行,并且我已经将目录与OSX中的Java源链接到虚拟Debian机器(使用Parallels工具,将目录挂载到/media/psf/).
编译工作正常,只有我遇到的问题是Maven Assembly插件:抱怨:
Failed to retrieve numeric file attributes using: '/bin/sh -c ls -1nlaR
Run Code Online (Sandbox Code Playgroud)
我搜索了以下问题:http://jira.codehaus.org/browse/MASSEMBLY-588
他们建议使用<directory>${baseDir}</directory>在jarlib.xml.通过此修改,代码可以编译,但在检查内容时jar tf file.jar,它完全缺少所有已编译的源,只添加了maven库.
在本地文件系统上正常工作的文件是:
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
有没有办法克服这个问题?
编辑:
Apache Maven 2.2.1 (rdebian-4)
Java version: 1.6.0_26
Java home: /usr/lib/jvm/java-6-sun-1.6.0.26/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-5-amd64" arch: "amd64" Family: "unix"
Run Code Online (Sandbox Code Playgroud) 这是对这些问题的跟进:
似乎 kapt 已经发展了,现在它甚至在 Maven 中得到支持。我正在尝试这个(注意配置中的 Lombok 注释处理器):
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessors>
<annotationProcessor>lombok.core.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
...
</plugin>
Run Code Online (Sandbox Code Playgroud)
但它似乎仍然没有效果,而且 Lombok@Getter仍然被忽略,如相关问题中所述。
有什么可以做的吗?
考虑两个类:
abstract class ParentRepository {}
class ChildRepository : ParentRepository {}
abstract class ParentClass {
protected abstract var repository: ParentRepository
}
class ChildClass : ParentClass {
override var repository: ChildRepository
}
Run Code Online (Sandbox Code Playgroud)
最后一部分不起作用:
override var repository: ChildRepository
Run Code Online (Sandbox Code Playgroud)
它会抱怨:
Type of 'repository' doesn't match the type of the overridden var-property 'protected abstract var repository: ParentRepository
Run Code Online (Sandbox Code Playgroud)
我理解这个问题,但我不明白为什么这不应该起作用 - ChildRepository 是 ParentRepository 的一个实例,这是我在 Java 中习惯的常见事物。
有没有办法top pods按节点过滤?
用例:我有一个节点,据报告它使用了 103% 的 cpu,我想验证是哪个 pod 导致了它。
java ×4
kotlin ×3
lombok ×2
spring ×2
android ×1
camera-flash ×1
hibernate ×1
kapt ×1
kubernetes ×1
maven ×1
mysql ×1
parallels ×1
transactions ×1