问题列表 - 第29946页

java线程同步问题,如何实现observable线程

问题是:C类控制B类是否允许B再次将A添加到queueOfA,但是如何确保当A的A通知C并在B的queueOfA变空之前立即更新,因为B类运行得如此之快以至于可能会删除所有的A,因此在C进行更新之前变为空队列,这可能会导致C的运行方法结束.

请帮帮我!

class A extends Observable implements Runnable{
    //...
    void run(){
     //...
     if ( goBackToTheQueueAgain == true ){
         setChanged();
         notifyObservers();//notify C that to let B add itself back
     }
    //...
}

class B extends implements Runnable{
    Queue<A> queueOfA;// initialy, queueOfA contains several A's
    //...
    void run(){
       //...
       A retrieved = queueOFA.remove();
       Thread aThread = new Thread(retrieved);
       aThread.start();
       //...
    }
 }

 class C implements Observer, Runnable {
    B b; //initially class C contains an instance of B 
    //...
    void update(Observable o, …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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

JSON格式化(通过jQuery AJAX发送JSON发布到Java/Wicket服务器)

我正在使用jQuery将JSON发布到Java服务器,但我认为我的JSON一定是错的.这是我的数据示例以及我如何发送它:

var lookup = {
    'name': name,
    'description': description,
    'items': [{
        'name': itemName,
        'value': itemValue
    }]
}

$.ajax({
    type: 'post',
    data: lookup,
    dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)

我正在使用Wicket的AbstractAjaxBehavior来接收数据,并希望得到一个我可以解析的JSON字符串.当我得到传递参数的Map时,键集如下所示:

items[0][name],
description,
name,
items[0][value],
Run Code Online (Sandbox Code Playgroud)

显然我可以很容易地获取名称和描述的值,但是我的项目数组的关键字搞砸了.我确信它很简单,但我似乎一直在解决这个问题.有什么建议?谢谢!

java ajax jquery json wicket

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

最有效的公钥加密方法

关于非对称公钥加密似乎有很多炒作.RSA,PGP ...等.您有一组两个密钥并分配一个密钥,因此只有您可以加密邮件只有您可以解密邮件.一种方法提供了验证发件人的方法,而另一种方法提供了一种保护邮件的方法.(如果我错了,请随意纠正我.)

现在,我也一直在阅读有关Diffie-Hellman类密钥交换的内容.这似乎更安全,因为您可以验证发件人并使用密钥保护邮件,因为每个"会话"都需要计算的"共享密钥".

所以,我的问题是,在更标准的公钥加密形式下使用Diffie-Hellman是否有任何重大缺点(除了设置要求)?

或者,更坦率地说.如果的Diffie-Hellman更有意义,为什么不是的标准形式的加密?

language-agnostic security encryption performance public-key

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

CountDownLatch InterruptedException

我正在使用CountDownLatch来同步两个线程之间的初始化过程,我想知道它可能抛出的InterruptedException的正确处理.

我最初写的代码是这样的:

    private CountDownLatch initWaitHandle = new CountDownLatch(1);
    /**
     * This method will block until the thread has fully initialized, this should only be called from different threads  Ensure that the thread has started before this is called.
     */
    public void ensureInitialized()
    {
        assert this.isAlive() : "The thread should be started before calling this method.";
        assert Thread.currentThread() != this, "This should be called from a different thread (potential deadlock)";
        while(true)
        {
            try
            {
                //we wait until …
Run Code Online (Sandbox Code Playgroud)

java multithreading exception-handling

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

分配供应配置文件待定

我已成功通过AdHoc Distrubution在iphone上测试我的应用程序,现在想要提交给AppStore.但是在为AppStore创建分发配置文件时存在问题.

创建此配置文件后,状态仍为PENDING.这需要多久?为AdHoc测试创建分发配置文件后没有延迟.

iphone profile distribution app-store

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

如果你可以将php嵌入到.html文件中,为什么要使用.php?

当你将php放入.html文件时,是否有某些原因可以将某些页面设为.php?它只是为了组织你的文件?或者它是否会影响页面的加载方式?

(我说的是文件扩展名)

html php embedding organization

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


PendingIntent对第一个通知正常工作,但对其余通知不正确

  protected void displayNotification(String response) {
    Intent intent = new Intent(context, testActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

    Notification notification = new Notification(R.drawable.icon, "Upload Started", System.currentTimeMillis());
    notification.setLatestEventInfo(context, "Upload", response, pendingIntent);

    nManager.notify((int)System.currentTimeMillis(), notification);
}
Run Code Online (Sandbox Code Playgroud)

该函数将被多次调用.我希望每个人notification在点击时启动testActivity.不幸的是,只有第一个通知启动testActivity.单击其余部分会导致通知窗口最小化.

额外信息:函数displayNotification()在一个叫做的类中UploadManager. 从实例化Context传递进来.函数在函数中多次调用,也在UploadManager中运行.UploadManageractivitydisplayNotification()AsyncTask

编辑1:我忘了提到我正在将String响应传递Intent intentextra.

  protected void displayNotification(String response) {
    Intent intent = new Intent(context, testActivity.class);
    intent.putExtra("response", response);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)

这有很大的不同,因为我需要额外的"响应"来反映创建通知时的字符串响应.相反,使用PendingIntent.FLAG_UPDATE_CURRENT,额外的"响应"反映了最后一次调用时String响应displayNotification().

我知道为什么这是通过阅读文档 …

notifications android android-pendingintent

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

禁用光标/编辑但保持对焦的能力

无论如何要实现跨浏览器的工作吗?(保持纯JavaScript,HTML和CSS的解决方案)我正在使用JQuery,所以JS就是最好的.

(disabled ="禁用"不允许焦点)

html javascript css jquery

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

LockFileEx 读/写升级/降级

我需要打开一个文件,对其进行读锁定,然后尝试获取写锁,但如果失败则保留读锁。

这在使用 fcntl 锁定的 POSIX 中非常有效。

在 Windows 中,我可以使用 LockFileEx 来获取文件锁。我可以获得读锁和写锁(共享锁和独占锁)。

不过,好像在Windows中我必须先拿独占写锁然后再加读锁。这与我在 POSIX 上执行的顺序相反,它会给我的抽象层带来问题。当我在 POSIX 中按照该顺序执行此操作时,我会通过获取读锁来丢失写锁,因为 fcntl 替换了现有锁,而不是像 Windows 那样添加锁。

我可以使用 #ifdefs 破解它来更改调用站点的锁定顺序,但我正在寻找好主意来修复我的抽象代码。

// This is the header file
struct LockFileImpl;
class LockFile {
    protected:
    boost::scoped_ptr<LockFileImpl> p;

    public:
    LockFile(const File &); 
    virtual ~LockFile();

    void unlock() const;
    void rd_lock() const;
    void wr_lock() const;
    bool rd_try() const;
    bool wr_try() const;
};

class LockFileRead : public LockFile{
    public:
    LockFileRead(const File &f) : LockFile(f)
    { rd_lock(); }
};

class LockFileWrite : public …
Run Code Online (Sandbox Code Playgroud)

c++ winapi locking

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