小编Edw*_*ale的帖子

在slf4j中设置运行时消息的日志级别

使用log4j时,该Logger.log(Priority p, Object message)方法可用,可用于在运行时确定的日志级别记录消息.我们正在使用这个事实和这个技巧将stderr重定向到特定日志级别的记录器.

slf4j没有log()我能找到的通用方法.这是否意味着无法实现上述目标?

java logging log4j slf4j

91
推荐指数
10
解决办法
10万
查看次数

ExecutorService在超时后中断任务

我正在寻找一个可以提供超时的ExecutorService实现.提交给ExecutorService的任务如果花费的时间超过运行超时,则会中断.实现这样的野兽不是一项艰巨的任务,但我想知道是否有人知道现有的实施.

以下是我根据下面的一些讨论提出的内容.任何意见?

import java.util.List;
import java.util.concurrent.*;

public class TimeoutThreadPoolExecutor extends ThreadPoolExecutor {
    private final long timeout;
    private final TimeUnit timeoutUnit;

    private final ScheduledExecutorService timeoutExecutor = Executors.newSingleThreadScheduledExecutor();
    private final ConcurrentMap<Runnable, ScheduledFuture> runningTasks = new ConcurrentHashMap<Runnable, ScheduledFuture>();

    public TimeoutThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, long timeout, TimeUnit timeoutUnit) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
        this.timeout = timeout;
        this.timeoutUnit = timeoutUnit;
    }

    public TimeoutThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, long timeout, …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading executorservice

87
推荐指数
3
解决办法
9万
查看次数

显示DialogFragment,动画从一个点开始增长

我正在显示DialogFragment当用户点击一行中的一行时ListView.我想为对话框的显示设置动画,使其从行的中心开始增长.从启动器打开文件夹时可以看到类似的效果.

,我已经有一个想法是组合TranslateAnimationScaleAnimation.还有另外一种方法吗?

android android-animation android-fragments

86
推荐指数
6
解决办法
9万
查看次数

通过谓词对集合进行分区的库方法

我有一个对象集合,我想分成两个集合,其中一个传递一个谓词,其中一个未通过谓词.我希望有一个Guava方法可以做到这一点,但它们最接近的是过滤器,它不会给我另一个集合.

我想图像方法的签名将是这样的:

public static <E> Pair<Collection<E>, Collection<E>> partition(Collection<E> source, Predicate<? super E> predicate)
Run Code Online (Sandbox Code Playgroud)

我意识到这对我自己的编码速度非常快,但我正在寻找一种能够实现我想要的现有库方法.

java collections guava

28
推荐指数
3
解决办法
8904
查看次数

使用CocoaPods的多个应用程序的项目/工作区结构

我即将迁移我的应用程序以使用CocoaPods.我当前的目录结构如下图所示.我有一个包含3个项目(一个工作空间ipad,ipod,common).有建立在目标ipadipod项目上的依赖common项目.

MyGreatApp
|
+-- MyGreatApp.xcworkspace
|
+-- ipad
|    |
|    +-- ipad.xcodeproj
|    +-- (source code)
|
+-- ipod
|    |
|    +-- ipod.xcodeproj
|    +-- (source code)
|
+-- common
     |
     +-- common.xcodeproj
     +-- (source code)
Run Code Online (Sandbox Code Playgroud)

我的问题是,我应该如何将其迁移到CocoaPods?看起来CocoaPods为Podfile您创建的每个创建一个新工作区.我想保留我的3项目工作区结构,因为它似乎可以很好地保持所有内容.我应该Podfile为每个项目创建一个目标和一个Specfile共同项目吗?我如何在XCode中设置它呢?

xcode ios cocoapods

25
推荐指数
1
解决办法
8909
查看次数

关于java上下文的委托示例

什么是Java授权?谁能给我一个恰当的例子?

java

23
推荐指数
2
解决办法
3万
查看次数

UITableView部分标题iOS 5

我有多个表委托给UIViewController.在IOS4中,我使用了函数:(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section更改某些表头部分的背景.在那些没有部分的人中,我返回零,一切正常.

在IOS5中,如果我返回nil,系统会放置一个默认的标题部分.如何隐藏我只有一个部分的表格中的标题部分?

iphone objective-c uitableview ios5

23
推荐指数
1
解决办法
1万
查看次数

当只有子类实现可序列化时,序列化如何工作

只有子类实现了Serializable接口.

import java.io.*;

public class NewClass1{

    private int i;
    NewClass1(){
    i=10;
    }
    int getVal() {
        return i;
    }
    void setVal(int i) {
        this.i=i;
    }
}

class MyClass extends NewClass1 implements Serializable{

    private String s;
    private NewClass1 n;

    MyClass(String s) {
        this.s = s;
        setVal(20);
    }

    public String toString() {
        return s + " " + getVal();
    }

    public static void main(String args[]) {
        MyClass m = new MyClass("Serial");
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("serial.txt"));
            oos.writeObject(m); …
Run Code Online (Sandbox Code Playgroud)

java inheritance serialization deserialization notserializableexception

23
推荐指数
2
解决办法
3万
查看次数

我可以在ivy.xml文件中使用属性来避免重复依赖项的版本号吗?

这是我的ivy.xml现在的样子:

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.context" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.jdbc" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.beans" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.jms" rev="3.0.2.RELEASE" />
Run Code Online (Sandbox Code Playgroud)

这是我希望它看起来像:

<dependency org="org.springframework" name="org.springframework.core" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.context" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.jdbc" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.beans" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.jms" rev="${spring.version}" />
Run Code Online (Sandbox Code Playgroud)

这可能吗?语法是什么?

apache dependencies ivy

21
推荐指数
2
解决办法
6183
查看次数

使用JdbcTemplate插入多行

如何使用在mySQL上运行的JdbcTemplate以可伸缩的方式执行以下SQL .在这种情况下,可扩展意味着:

  1. 服务器上只执行一条SQL语句
  2. 它适用于任意数量的行.

这是声明:

INSERT INTO myTable (foo, bar) VALUES ("asdf", "asdf"), ("qwer", "qwer")
Run Code Online (Sandbox Code Playgroud)

假设我有一个POJO的列表foobar字段.我意识到我可以迭代列表并执行:

jdbcTemplate.update("INSERT INTO myTable(foo, bar) VALUES (?, ?)", paramMap)
Run Code Online (Sandbox Code Playgroud)

但这并不能完成第一个标准.

我相信我也可以执行:

jdbcTemplate.batchUpdate("INSERT INTO myTable(foo, bar) VALUES (?, ?)", paramMapArray)
Run Code Online (Sandbox Code Playgroud)

但据我所知,这只会编译SQL一次并多次执行,再次失败第一个标准.

似乎通过这两个标准的最终可能性是简单地用a构建SQL StringBuffer,但我想避免这种情况.

java sql spring jdbc jdbctemplate

20
推荐指数
3
解决办法
4万
查看次数