小编Sou*_*abh的帖子

如何从卡夫卡的旧偏移点获取数据?

我正在使用zookeeper从kafka获取数据.在这里,我总是从最后一个偏移点获取数据.有没有办法指定偏移时间来获取旧数据?

有一个选项autooffset.reset.它接受最小或最大.有人可以解释什么是最小和最大的.autooffset.reset可以帮助从旧的偏移点而不是最新的偏移点获取数据吗?

offset apache-kafka apache-zookeeper zookeeper

35
推荐指数
2
解决办法
4万
查看次数

使用线程进行奇数偶数打印

奇数偶数打印使用thread.Create一个线程类,两个线程实例.一个将打印奇数,另一个将打印偶数.

我做了以下编码.但它涉及死锁状态.有人可以解释一下可能是什么原因吗?

public class NumberPrinter implements Runnable{
private String type;
private static boolean oddTurn=true;


public NumberPrinter(String type){
    this.type=type;
}
public void run() {
    int i=type.equals("odd")?1:2;
    while(i<10){
        if(type.equals("odd"))
            printOdd(i);
        if(type.equals("even"))
            printEven(i);
        i=i+2;
    }

}

private synchronized void printOdd(int i){
    while(!oddTurn){
        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println(type + i);
    oddTurn=false;
    notifyAll();
}

private synchronized  void printEven(int i){
    while(oddTurn){
        try {
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace(); 
        }
    }
    System.out.println(type + i);
    oddTurn=true;
    notifyAll();

}

public …
Run Code Online (Sandbox Code Playgroud)

java multithreading thread-safety

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

在每个测试规范之后,Jasmine不会重置间谍

我有以下规格.

describe("SN.ExitHistory", function() {

    var exitHistory;

    beforeEach(function() {

    SN.Utils = jasmine.createSpy("utils").andCallFake(function() {
        function readSNCookie(cookieName, key) {
            return "google.com";
        }

        function isUndefinedOrNull(param) {
            return (param == null) || (param === "null");
        }

        function createSNCookie(snCookieName, key, value, lifeTime) {

        }

        var me = {
            readSNCookie : readSNCookie,
            isUndefinedOrNull : isUndefinedOrNull,
            createSNCookie : createSNCookie
        };
        return me;

    })();

    exitHistory = SN.ExitHistory();

    });

    it("return last exit link", function() {
        expect(exitHistory.getLastExitLink()).toEqual("google.com");
    });

 });
Run Code Online (Sandbox Code Playgroud)

exitHistory.getLastExitLink内部使用SN.Utils.

测试完成后,Jasmine不会删除间谍对象utils.在下一个测试套件中,我也可以看到相同的工具.有没有办法在每次测试完成后重置间谍对象?

如果我为utils创建一个新对象,而不是创建间谍,行为是相同的.那么这个场景中间谍和实际对象之间的区别是什么.

如果我错了,请纠正我.

javascript testing junit unit-testing jasmine

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

struts2列表框中的默认值

我们有列表框.这将显示美国的不同州.我希望状态"LA"应该被预选.但我不知道列表中"LA"的位置.它可能会有所不同.我们正在使用以下脚本.

<select id="state" name="state" title="State" class="js_required prompt_text grid_2" tabindex="5">
                <option>State</option>
                <s:iterator value="@com.homeservices.action.utils.StateCode@values()">
                    <option value="<s:property/>"><s:property/></option>
                </s:iterator>
</select>
Run Code Online (Sandbox Code Playgroud)

var @ com.homeservices.action.utils.StateCode @ values()给出了一个值列表:

AA
AE
AK
CA
CT
IL
LA
MA
MD
Run Code Online (Sandbox Code Playgroud)

......等等.

有人可以建议如何使洛杉矶成为一个预先选定的州.

jsp struts struts2 listbox jsp-tags

3
推荐指数
1
解决办法
1757
查看次数

如果文件存在,则将外壳中的输出重定向到另一个文件

我正在使用以下命令将输出重定向到另一个文件。

ls -l >>foo.txt
Run Code Online (Sandbox Code Playgroud)

此命令会将输出附加ls -l到foo.txt。如果该文件不存在,它将创建一个新文件foo.txt并将输出重定向到新的foo.txt。

现在,只有在文件已经存在的情况下,才可以将文件的输出重定向/追加ls -l到文件中,否则它将无法重定向输出或将其丢弃

就我而言,如果foo.txt已经存在,它将输出附加到foo.txt,否则它将丢弃输出。

有命令执行此操作吗?

unix linux shell redirect

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