小编Gil*_*ili的帖子

JLayeredPane与Container分层

JLayeredPane允许使用JLayeredPane.add(Component,Integer)将多个组件堆叠在一起.较高"层"中的组件显示在较低"层"中的组件顶部.

Container.add(Component,int)提供了一种类似的机制,其中具有较低索引的组件显示在具有较高索引的组件之上.

请注意,第一种机制使用Integer,第二种机制使用int.另外,一个在低值之上呈现高值,而另一个则相反.不要混两个:)

我的问题是:当Container已经提供相同的机制时,使用JLayeredPane有什么意义?一层组件比另一层好吗?

更新:还要考虑Container.setComponentZOrder(Component,int).

java swing

7
推荐指数
1
解决办法
2030
查看次数

为什么"hg推"比.hg大得多?

我的项目.hg目录是40MB.如果我hg push --verbose --debug是一个空的远程存储库,我看到它发送了数百MB.额外的开销来自哪里?

更新:hg bundle -a生成35MB文件.这是我看到的输出的精简版本:

pushing to https://jace.googlecode.com/hg/
using https://jace.googlecode.com/hg/
sending between command
using auth.default.* for authentication
jace.googlecode.com certificate successfully verified
sending capabilities command
using auth.default.* for authentication
capabilities: branchmap lookup unbundle=HG10UN,HG10UGZ,HG10BZ changegroupsubset
sending heads command
using auth.default.* for authentication
searching for changes
common changesets up to 71818a195bf5
sending branchmap command
[...]
bundling: <filenames>
sending unbundle command
sending xxx bytes
[...]
sending: xxx/xxx kb
Run Code Online (Sandbox Code Playgroud)

mercurial

7
推荐指数
1
解决办法
644
查看次数

Jetty:检测Webapp是否无法启动

我正在启动一个包含单个webapp的嵌入式Jetty实例.webapp在启动时启动.我想知道如何检测Webapp的contextInitialized是否会引发异常.

当webapp抛出异常时,Server.start()不会,server.isRunning()返回true.有没有办法让我从容器外听取webapp异常?

servlets jetty

7
推荐指数
2
解决办法
1013
查看次数

如何使用CompletableFuture.thenComposeAsync()?

鉴于:

public class Test
{
    public static void main(String[] args)
    {
        int nThreads = 1;
        Executor e = Executors.newFixedThreadPool(nThreads);

        CompletableFuture.runAsync(() ->
        {
            System.out.println("Task 1. Thread: " + Thread.currentThread().getId());
        }, e).thenComposeAsync((Void unused) ->
        {
            return CompletableFuture.runAsync(() ->
            {
                System.out.println("Task 2. Thread: " + Thread.currentThread().getId());
            }, e);
        }, e).join();
        System.out.println("finished");
    }
}
Run Code Online (Sandbox Code Playgroud)

我期待一个执行程序线程运行任务1,然后执行任务2.相反,代码挂起,如果nThreads小于2.

  1. 请解释代码挂起的原因.我可以看到它在CompletableFuture中被阻止:616等待一些Future完成,但目前尚不清楚原因.
  2. 如果我允许使用2个线程,那么每个线程用于什么?

总之,请帮助我了解thenComposeAsync()实际工作原理.Javadoc看起来像是为机器人而不是人类而写的:)

java multithreading future java-8

7
推荐指数
2
解决办法
4294
查看次数

如何在ForkJoinPool中使用MDC?

关注如何在线程池中使用MDC?如何使用MDC ForkJoinPool?具体来说,我怎么能ForkJoinTask在执行任务之前设置一个这样的MDC值?

java slf4j mdc fork-join

7
推荐指数
1
解决办法
2108
查看次数

如何为 Maven 插件指定默认目标?

我定义了一个具有多个目标的 Maven 插件。目前用户运行我的插件如下:

<plugin>
    <groupId>myGroupId</groupId>
    <artifactId>myArtifactId</artifactId>
    <version>someVersion</version>
    <executions>
        <execution>
            <goals>
                <goal>myGoal</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但我见过其他插件,比如maven-compiler-pluginFlyway,不需要指定executionhttps : //flywaydb.org/getstarted/java

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>5.2.4</version>
    <configuration>
        <url>jdbc:h2:file:./target/foobar</url>
        <user>sa</user>
        <locations>
            <location>classpath:db/migration</location>
        </locations>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当用户排除<executions>块时,如何指定默认运行的目标?

mojo maven

7
推荐指数
1
解决办法
1603
查看次数

如何定义自己的SelectableChannel?

我如何定义新类型java.nio.channels.SelectableChannel(比如串口)?

java nio

6
推荐指数
1
解决办法
1871
查看次数

Ant:将类名转换为文件路径

如何使用Ant任务将Java类名转换为文件路径?

例如,给定一个包含foo.bar.Duck我想要出去的属性foo/bar/Duck.class.

我试图(和失败)中的条款来实现这个<pathconvert><regexpmapper>.

ant

6
推荐指数
1
解决办法
1065
查看次数

如何使任意URL的缓存失效?

根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10,客户端必须在 POST、PUT 或 DELETE 请求后使与 URL 关联的缓存无效。

是否可以指示 Web 浏览器使任意 URL 的缓存失效,而不向其发出 HTTP 请求?

例如:

  1. PUT /companies/Nintendo创建一家名为“任天堂”的新公司
  2. GET /companies列出所有公司
  3. 每次我创建一个新公司时,我都希望使与GET /companies. 浏览器不会自动执行此操作,因为两者在不同的 URL 上运行。

Cache-Control机制是否不适合这种情况?我应该使用no-cachewithETag来代替吗?对于这种情况,最佳做法是什么?

no-cache我知道下次可以通过,GET /companies但这需要应用程序跟踪 URL 失效,而不是将责任推给浏览器。意思是,我想在步骤 1 之后使 URL 失效,而不是必须保留此信息并在步骤 2 中应用它。有什么想法吗?

ajax rest http cache-control

6
推荐指数
1
解决办法
1233
查看次数

为什么 LambdaMetafactory 在使用自定义函数接口时会失败(但 Function 工作正常)?

鉴于:

import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.function.Function;

class Testcase
{
    @FunctionalInterface
    public interface MyBuilder1<R>
    {
        R apply(String message);
    }

    @FunctionalInterface
    public interface MyBuilder2<R>
    {
        R apply(Object message);
    }

    public static void main(String[] args) throws Throwable
    {
        Class<?> clazz = IllegalArgumentException.class;

        MethodHandles.Lookup lookup = MethodHandles.lookup();
        MethodHandle mh = lookup.findConstructor(clazz, MethodType.methodType(void.class, String.class));
        MethodHandle myFunctionConstructor = LambdaMetafactory.metafactory(
            lookup,
            "apply",
            MethodType.methodType(Function.class),
            mh.type().erase(),
            mh,
            mh.type()
        ).getTarget();

        MethodHandle myBuilderConstructor1 = LambdaMetafactory.metafactory(
            lookup,
            "apply",
            MethodType.methodType(MyBuilder1.class),
            mh.type().erase(),
            mh,
            mh.type()
        ).getTarget();

        MethodHandle myBuilderConstructor2 = LambdaMetafactory.metafactory( …
Run Code Online (Sandbox Code Playgroud)

java methodhandle lambda-metafactory

6
推荐指数
1
解决办法
389
查看次数